@@ -40,34 +40,44 @@ EqualityTest varEqualityTestExpr(SsaVariable v1, SsaVariable v2, boolean isEqual
40
40
isEqualExpr = result .polarity ( )
41
41
}
42
42
43
- /** Gets an expression that is provably not `null`. */
44
- Expr clearlyNotNullExpr ( Expr reason ) {
45
- result instanceof ClassInstanceExpr and reason = result
43
+ Expr baseNotNullExpr ( ) {
44
+ result instanceof ClassInstanceExpr
46
45
or
47
- result instanceof ArrayCreationExpr and reason = result
46
+ result instanceof ArrayCreationExpr
48
47
or
49
- result instanceof TypeLiteral and reason = result
48
+ result instanceof TypeLiteral
50
49
or
51
- result instanceof ThisAccess and reason = result
50
+ result instanceof ThisAccess
52
51
or
53
- result instanceof StringLiteral and reason = result
52
+ result instanceof StringLiteral
54
53
or
55
- result instanceof AddExpr and result .getType ( ) instanceof TypeString and reason = result
54
+ result instanceof AddExpr and result .getType ( ) instanceof TypeString
56
55
or
57
56
exists ( Field f |
58
57
result = f .getAnAccess ( ) and
59
58
( f .hasName ( "TRUE" ) or f .hasName ( "FALSE" ) ) and
60
- f .getDeclaringType ( ) .hasQualifiedName ( "java.lang" , "Boolean" ) and
61
- reason = result
59
+ f .getDeclaringType ( ) .hasQualifiedName ( "java.lang" , "Boolean" )
62
60
)
63
61
or
64
- result . ( CastExpr ) . getExpr ( ) = clearlyNotNullExpr ( reason )
62
+ result = any ( EnumConstant c ) . getAnAccess ( )
65
63
or
66
- result . ( ImplicitCastExpr ) . getExpr ( ) = clearlyNotNullExpr ( reason )
64
+ result instanceof ImplicitNotNullExpr
67
65
or
68
- result instanceof ImplicitNotNullExpr and reason = result
66
+ result instanceof ImplicitCoercionToUnitExpr
69
67
or
70
- result instanceof ImplicitCoercionToUnitExpr and reason = result
68
+ result
69
+ .( MethodCall )
70
+ .getMethod ( )
71
+ .hasQualifiedName ( "com.google.common.base" , "Strings" , "nullToEmpty" )
72
+ }
73
+
74
+ /** Gets an expression that is provably not `null`. */
75
+ Expr clearlyNotNullExpr ( Expr reason ) {
76
+ result = baseNotNullExpr ( ) and reason = result
77
+ or
78
+ result .( CastExpr ) .getExpr ( ) = clearlyNotNullExpr ( reason )
79
+ or
80
+ result .( ImplicitCastExpr ) .getExpr ( ) = clearlyNotNullExpr ( reason )
71
81
or
72
82
result .( AssignExpr ) .getSource ( ) = clearlyNotNullExpr ( reason )
73
83
or
@@ -83,14 +93,14 @@ Expr clearlyNotNullExpr(Expr reason) {
83
93
guard .controls ( rval .getBasicBlock ( ) , branch ) and
84
94
reason = guard and
85
95
rval = v .getAUse ( ) and
86
- result = rval
96
+ result = rval and
97
+ not result = baseNotNullExpr ( )
87
98
)
88
99
or
89
- exists ( SsaVariable v | clearlyNotNull ( v , reason ) and result = v .getAUse ( ) )
90
- or
91
- exists ( Method m | m = result .( MethodCall ) .getMethod ( ) and reason = result |
92
- m .getDeclaringType ( ) .hasQualifiedName ( "com.google.common.base" , "Strings" ) and
93
- m .hasName ( "nullToEmpty" )
100
+ exists ( SsaVariable v |
101
+ clearlyNotNull ( v , reason ) and
102
+ result = v .getAUse ( ) and
103
+ not result = baseNotNullExpr ( )
94
104
)
95
105
}
96
106
0 commit comments