File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed
src/Likely Bugs/Arithmetic Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import semmle.code.java.deadcode.DeadEnumConstant
3
3
import semmle.code.java.deadcode.DeadCodeCustomizations
4
4
import semmle.code.java.deadcode.DeadField
5
5
import semmle.code.java.deadcode.EntryPoints
6
+ private import semmle.code.java.frameworks.kotlin.Serialization
6
7
7
8
/**
8
9
* Holds if the given callable has any liveness causes.
@@ -309,10 +310,7 @@ class RootdefCallable extends Callable {
309
310
this .isCompilerGenerated ( )
310
311
or
311
312
// Exclude Kotlin serialization constructors.
312
- this .( Constructor )
313
- .getParameterType ( this .getNumberOfParameters ( ) - 1 )
314
- .( RefType )
315
- .hasQualifiedName ( "kotlinx.serialization.internal" , "SerializationConstructorMarker" )
313
+ this instanceof SerializationConstructor
316
314
}
317
315
}
318
316
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Provides classes and predicates for working with thi `kotlinx.serialization` plugin.
3
+ */
4
+
5
+ import java
6
+
7
+ /**
8
+ * A constructor with a `SerializationConstructorMarker` parameter.
9
+ */
10
+ class SerializationConstructor extends Constructor {
11
+ SerializationConstructor ( ) {
12
+ this .getParameterType ( this .getNumberOfParameters ( ) - 1 )
13
+ .( RefType )
14
+ .hasQualifiedName ( "kotlinx.serialization.internal" , "SerializationConstructorMarker" )
15
+ }
16
+ }
Original file line number Diff line number Diff line change 10
10
*/
11
11
12
12
import java
13
+ private import semmle.code.java.frameworks.kotlin.Serialization
13
14
14
15
int eval ( Expr e ) { result = e .( CompileTimeConstantExpr ) .getIntValue ( ) }
15
16
59
60
// Exclude explicit zero multiplication.
60
61
not e .( MulExpr ) .getAnOperand ( ) .( IntegerLiteral ) .getIntValue ( ) = 0 and
61
62
// Exclude expressions that appear to be disabled deliberately (e.g. `false && ...`).
62
- not e .( AndLogicalExpr ) .getAnOperand ( ) .( BooleanLiteral ) .getBooleanValue ( ) = false
63
+ not e .( AndLogicalExpr ) .getAnOperand ( ) .( BooleanLiteral ) .getBooleanValue ( ) = false and
64
+ // Exclude expressions that are in serialization constructors, which are auto-generated.
65
+ not e .getEnclosingCallable ( ) instanceof SerializationConstructor
63
66
select e , "Expression always evaluates to the same value."
You can’t perform that action at this time.
0 commit comments