-
Bug
-
Resolution: Not an Issue
-
P5
-
None
-
21, 25
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
openSUSE Tumbleweed (Linux)
Java 21.0.7, 24.0.1
A DESCRIPTION OF THE PROBLEM :
When a Java source file is compiled using javac -Xlint:all, it should emit three warnings: two [cast] and one [this-escape]. However, when compiled in modular mode (with --module, --module-source-path), javac omits the [this-escape] warning.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create the directory structure:
$ mkdir -p javac-bug/src/test/java/org/foo/bar
2. Create module-info.java in javac-bug/src/test/java/
module test {
}
3. Create TestEscapeWarning.java in javac-bug/src/test/java/org/foo/bar/:
package org.foo.bar;
public class TestEscapeWarning {
private int v1;
private int v2;
public TestEscapeWarning(int v1, int v2) {
this.v1 = (int)v1; // to issue a [cast] warning
this.v2 = (int)v2; // to issue a [cast] warning
if (foo(v1,v2) > 0) { // to issue a [this-escape] warning
}
}
protected int foo(int x, int y) {
return x-y;
}
}
4.Change directory:
$ cd javac-bug
5. Compile in classic (non-modular) mode (will emit 3 warnings) :
$ javac -d build -classpath . -g:none -Xlint:all src/test/java/org/foo/bar/TestEscapeWarning.java
src/test/java/org/foo/bar/TestEscapeWarning.java:8: warning: [cast] redundant cast to int
this.v1 = (int)v1; // to issue a [cast] warning
^
src/test/java/org/foo/bar/TestEscapeWarning.java:9: warning: [cast] redundant cast to int
this.v2 = (int)v2; // to issue a [cast] warning
^
src/test/java/org/foo/bar/TestEscapeWarning.java:11: warning: [this-escape] possible 'this' escape before subclass is fully initialized
if (foo(v1,v2) > 0) { // to issue a [this-escape] warning
^
3 warnings
6. Compile in modular mode (will emit 2 warnings):
$ javac -d build -classpath . -g:none --module=test -Xlint:all --module-source-path "src/*/java/" --module=test
src/test/java/org/foo/bar/TestEscapeWarning.java:8: warning: [cast] redundant cast to int
this.v1 = (int)v1; // to issue a [cast] warning
^
src/test/java/org/foo/bar/TestEscapeWarning.java:9: warning: [cast] redundant cast to int
this.v2 = (int)v2; // to issue a [cast] warning
^
2 warnings
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All three warnings (2 × [cast], 1 × [this-escape]) should be emitted in both classic and modular compilation modes.
ACTUAL -
In modular compilation mode, the [this-escape] warning is not emitted.
---------- BEGIN SOURCE ----------
Included inline in “Steps to Reproduce.”
---------- END SOURCE ----------
openSUSE Tumbleweed (Linux)
Java 21.0.7, 24.0.1
A DESCRIPTION OF THE PROBLEM :
When a Java source file is compiled using javac -Xlint:all, it should emit three warnings: two [cast] and one [this-escape]. However, when compiled in modular mode (with --module, --module-source-path), javac omits the [this-escape] warning.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create the directory structure:
$ mkdir -p javac-bug/src/test/java/org/foo/bar
2. Create module-info.java in javac-bug/src/test/java/
module test {
}
3. Create TestEscapeWarning.java in javac-bug/src/test/java/org/foo/bar/:
package org.foo.bar;
public class TestEscapeWarning {
private int v1;
private int v2;
public TestEscapeWarning(int v1, int v2) {
this.v1 = (int)v1; // to issue a [cast] warning
this.v2 = (int)v2; // to issue a [cast] warning
if (foo(v1,v2) > 0) { // to issue a [this-escape] warning
}
}
protected int foo(int x, int y) {
return x-y;
}
}
4.Change directory:
$ cd javac-bug
5. Compile in classic (non-modular) mode (will emit 3 warnings) :
$ javac -d build -classpath . -g:none -Xlint:all src/test/java/org/foo/bar/TestEscapeWarning.java
src/test/java/org/foo/bar/TestEscapeWarning.java:8: warning: [cast] redundant cast to int
this.v1 = (int)v1; // to issue a [cast] warning
^
src/test/java/org/foo/bar/TestEscapeWarning.java:9: warning: [cast] redundant cast to int
this.v2 = (int)v2; // to issue a [cast] warning
^
src/test/java/org/foo/bar/TestEscapeWarning.java:11: warning: [this-escape] possible 'this' escape before subclass is fully initialized
if (foo(v1,v2) > 0) { // to issue a [this-escape] warning
^
3 warnings
6. Compile in modular mode (will emit 2 warnings):
$ javac -d build -classpath . -g:none --module=test -Xlint:all --module-source-path "src/*/java/" --module=test
src/test/java/org/foo/bar/TestEscapeWarning.java:8: warning: [cast] redundant cast to int
this.v1 = (int)v1; // to issue a [cast] warning
^
src/test/java/org/foo/bar/TestEscapeWarning.java:9: warning: [cast] redundant cast to int
this.v2 = (int)v2; // to issue a [cast] warning
^
2 warnings
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All three warnings (2 × [cast], 1 × [this-escape]) should be emitted in both classic and modular compilation modes.
ACTUAL -
In modular compilation mode, the [this-escape] warning is not emitted.
---------- BEGIN SOURCE ----------
Included inline in “Steps to Reproduce.”
---------- END SOURCE ----------
- relates to
-
JDK-8299995 Add lint check for calling overridable methods from a constructor
-
- Closed
-