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
33import semmle.code.java.deadcode.DeadCodeCustomizations
44import semmle.code.java.deadcode.DeadField
55import semmle.code.java.deadcode.EntryPoints
6+ private import semmle.code.java.frameworks.kotlin.Serialization
67
78/**
89 * Holds if the given callable has any liveness causes.
@@ -309,10 +310,7 @@ class RootdefCallable extends Callable {
309310 this .isCompilerGenerated ( )
310311 or
311312 // Exclude Kotlin serialization constructors.
312- this .( Constructor )
313- .getParameterType ( this .getNumberOfParameters ( ) - 1 )
314- .( RefType )
315- .hasQualifiedName ( "kotlinx.serialization.internal" , "SerializationConstructorMarker" )
313+ this instanceof SerializationConstructor
316314 }
317315}
318316
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 1010 */
1111
1212import java
13+ private import semmle.code.java.frameworks.kotlin.Serialization
1314
1415int eval ( Expr e ) { result = e .( CompileTimeConstantExpr ) .getIntValue ( ) }
1516
5960 // Exclude explicit zero multiplication.
6061 not e .( MulExpr ) .getAnOperand ( ) .( IntegerLiteral ) .getIntValue ( ) = 0 and
6162 // 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
6366select e , "Expression always evaluates to the same value."
You can’t perform that action at this time.
0 commit comments