eclipse-jdt / eclipse-jdt/eclipse.jdt.core

Implement "this-escape" warnings

Open
#3,950 3 comments 0 reactions 1 assignee Claimed by @stephan-herrmann View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

See https://bugs.openjdk.org/browse/JDK-8015831 "Add lint check for calling overridable methods from a constructor"

My first guess that javac would emit this warning in situations like this:
```java
public class Y {
Y() {
System.out.print("Y-pre");
m();
}
void m() {}
}
```
```java
public class X extends Y {
String s = "Hello";
X() {
super();
}
@Override void m() {
System.out.print(s);
}
public static void main(String... args) {
System.out.print(new X().s);
}

}
```

Interestingly, `javac -Xlint:all Y.java X.java` keeps quiet!! And happily prints `Y-prenullHello`, i.e., it doesn't detect that `s` is read before initializaed.

Still the have a complex test case in https://github.com/archiecobbs/jdk/blob/ThisEscape/test/langtools/tools/javac/warnings/ThisEscape.java that triggers plenty of these warnings.

Need to figure out what should be the rules.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.