-
Bug
-
Resolution: Won't Fix
-
P4
-
17, 18
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
javac --version
javac 18.0.1
A DESCRIPTION OF THE PROBLEM :
When compiling code that has a record involved in cyclic inheritance, an error is produced that implies that the user placed the "private" modifier although no such modifier exists in the code.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attached are two example programs, one minimal and one showing a reasonable (enough) use case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Just the error around cyclic inheritance to appear, although how exactly it is cyclical is very unclear from the message.
ACTUAL -
$ javac A.java
A.java:1: error: cyclic inheritance involving A
public record A(int b) implements A.C {
^
A.java:1: error: modifier private not allowed here
public record A(int b) implements A.C {
^
2 errors
$ javac Program.java
Program.java:6: error: cyclic inheritance involving Program
public record Program(List<Rule> b) implements Program.ParseResult {
^
Program.java:6: error: modifier private not allowed here
public record Program(List<Rule> b) implements Program.ParseResult {
---------- BEGIN SOURCE ----------
A.java
public record A(int b) implements A.C {
interface C {}
}
Program.java
import java.util.List;
record Rule() {}
public record Program(List<Rule> b) implements Program.ParseResult {
sealed interface ParseResult {}
enum ParseFailure implements ParseResult {
SPECIFIC_ERROR
};
static ParseResult parse(String program) {
if (program.isEmpty()) {
return ParseFailure.SPECIFIC_ERROR;
}
else {
return new Program(List.of());
}
}
}
---------- END SOURCE ----------
javac --version
javac 18.0.1
A DESCRIPTION OF THE PROBLEM :
When compiling code that has a record involved in cyclic inheritance, an error is produced that implies that the user placed the "private" modifier although no such modifier exists in the code.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attached are two example programs, one minimal and one showing a reasonable (enough) use case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Just the error around cyclic inheritance to appear, although how exactly it is cyclical is very unclear from the message.
ACTUAL -
$ javac A.java
A.java:1: error: cyclic inheritance involving A
public record A(int b) implements A.C {
^
A.java:1: error: modifier private not allowed here
public record A(int b) implements A.C {
^
2 errors
$ javac Program.java
Program.java:6: error: cyclic inheritance involving Program
public record Program(List<Rule> b) implements Program.ParseResult {
^
Program.java:6: error: modifier private not allowed here
public record Program(List<Rule> b) implements Program.ParseResult {
---------- BEGIN SOURCE ----------
A.java
public record A(int b) implements A.C {
interface C {}
}
Program.java
import java.util.List;
record Rule() {}
public record Program(List<Rule> b) implements Program.ParseResult {
sealed interface ParseResult {}
enum ParseFailure implements ParseResult {
SPECIFIC_ERROR
};
static ParseResult parse(String program) {
if (program.isEmpty()) {
return ParseFailure.SPECIFIC_ERROR;
}
else {
return new Program(List.of());
}
}
}
---------- END SOURCE ----------