The "this-escape" warning logic fails to suppress a warning that should be suppressed by @SuppressWarnings("this-escape") when the warning happens via a field initializer, all analyzable primary constructors are annotated with @SuppressWarnings("this-escape"), and at least one analyzable non-primary constructor is not annotated with @SuppressWarnings("this-escape").
Here's an example of that happening:
public class ThisEscape {
private final int foo = leak();
public ThisEscape() {
this("");
}
@SuppressWarnings("this-escape")
private ThisEscape(String s) {
}
public int leak() {
return 1;
}
}
ThisEscape.java:4: warning: [this-escape] possible 'this' escape before subclass is fully initialized
private final int foo = leak();
^
1 warning
The compiler currently reports a leak at "foo" but it shouldn't - the initialization of "foo" happens within the second constructor which is annotated with @SuppressWarnings("this-escape").
Here's an example of that happening:
public class ThisEscape {
private final int foo = leak();
public ThisEscape() {
this("");
}
@SuppressWarnings("this-escape")
private ThisEscape(String s) {
}
public int leak() {
return 1;
}
}
ThisEscape.java:4: warning: [this-escape] possible 'this' escape before subclass is fully initialized
private final int foo = leak();
^
1 warning
The compiler currently reports a leak at "foo" but it shouldn't - the initialization of "foo" happens within the second constructor which is annotated with @SuppressWarnings("this-escape").
- links to
-
Review(master) openjdk/jdk/24932