eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Illegal override of final method produces illegal bytecode
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
From https://bugs.eclipse.org/bugs/show_bug.cgi?id=163365:
```
class Y {
final public void foo() {
}
}
public class X extends Y {
public void foo() {}
public static void main(String[] args) {
new X().foo();
}
}
```
Compiling this code (in the IDE, or when using the batch compiler with `-proceedOnError`) actually creates that illegal method `foo()` with this as the substituted method body: `throw new Error("String Unresolved compilation problem: \n\tCannot override the final method from Y");`. But that method body doesn't prevent this at runtime:
```
Error: LinkageError occurred while loading main class X
java.lang.IncompatibleClassChangeError: class X overrides final method Y.foo()V
```
As discussed in bugzilla, we need to find a better way to signal the error, since we are not allowed to generate that method `foo()`.
Contributor guide
Assessment
This issue has not been assessed yet.