File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
src/Likely Bugs/Concurrency
test/query-tests/StartInConstructor Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 15
15
16
16
import java
17
17
18
+ private predicate hasASubclass ( RefType t ) {
19
+ exists ( RefType sub | sub != t | sub .getAnAncestor ( ) = t )
20
+ }
21
+
18
22
/**
19
23
* Holds if this type is either `final` or
20
24
* `private` and without subtypes.
@@ -24,7 +28,11 @@ private predicate cannotBeExtended(RefType t) {
24
28
or
25
29
// If the class is private, all possible subclasses are known.
26
30
t .isPrivate ( ) and
27
- not exists ( RefType sub | sub != t | sub .getAnAncestor ( ) = t )
31
+ not hasASubclass ( t )
32
+ or
33
+ // If the class only has private construtors, all possible subclasses are known.
34
+ forex ( Constructor c | c .getDeclaringType ( ) = t | c .isPrivate ( ) ) and
35
+ not hasASubclass ( t )
28
36
}
29
37
30
38
from MethodCall m , Constructor c , Class clazz
Original file line number Diff line number Diff line change @@ -30,4 +30,18 @@ public Private() {
30
30
}
31
31
32
32
}
33
- }
33
+
34
+ public static class AllPrivateConstructors {
35
+ Thread myThread ;
36
+
37
+ private AllPrivateConstructors () {
38
+ myThread = new Thread ("myThread" );
39
+ // OK - class cannot be extended outside this file, and is not in fact extended
40
+ myThread .start ();
41
+ }
42
+
43
+ public static AllPrivateConstructors create () {
44
+ return new AllPrivateConstructors ();
45
+ }
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments