A DESCRIPTION OF THE PROBLEM :
As mentioned in JShell User's Guide (https://docs.oracle.com/en/java/javase/19/jshell/snippets.html), JShell will display an error message while attempting to use malformed overwritten variables, methods and classes. For example:
$ jshell
| Welcome to JShell -- Version 19.0.1
| For an introduction type: /help intro
jshell> int foo = 42;
foo ==> 42
jshell> int getFoo() { return foo;}
| created method getFoo()
jshell> double foo = 42.0
foo ==> 42.0
jshell> getFoo()
| attempted to call method getFoo() which cannot be invoked until this error is corrected:
| incompatible types: possible lossy conversion from double to int
| int getFoo() { return foo;}
| ^-^
However, errors about overriding and hierarchy are not displayed by default, but instead display a "cannot find symbol" error. These include:
a) A method is overridden by a method with incompatible return type
b) Interfaces appear in `extends` clause
c) A class appears in `implements` clause
d) A subclass of an abstract class does not override abstract methods
e) @Override is annotated on a method that does not override
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run jshell without any options, and input code shown in "Source Code" section.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
For example, for the last line in case a, it should display a message like:
| attempted to reference class Bar which cannot be referenced until this error is corrected:
| method() in Bar cannot override method() in Foo
| return type void is not compatible with int
| void method() {}
| ^--------------^
ACTUAL -
For the last line in all cases, it displays:
| Error:
| cannot find symbol
| symbol: class Bar
| new Bar()
| ^-^
---------- BEGIN SOURCE ----------
// Case a:
class Foo {
void method() {}
}
class Bar extends Foo {
void method() {}
}
class Foo {
int method() { return 0; }
}
new Bar() // This line should display "cannot be referenced until this error is corrected" message
// Case b:
class Foo {}
class Bar extends Foo {}
interface Foo {}
new Bar() // This line should display "cannot be referenced until this error is corrected" message
// Case c:
interface Foo {}
class Bar implements Foo {}
class Foo {}
new Bar() // This line should display "cannot be referenced until this error is corrected" message
// Case d:
class Foo {
void method() {}
}
class Bar extends Foo {}
abstract class Foo {
abstract void method();
}
new Bar() // This line should display "cannot be referenced until this error is corrected" message
// Case e:
class Foo {
void method() {}
}
class Bar extends Foo {
@Override void method() {}
}
class Foo {}
new Bar() // This line should display "cannot be referenced until this error is corrected" message
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Add -v option (it displays the error message only when you make subclasses malformed)
FREQUENCY : always
As mentioned in JShell User's Guide (https://docs.oracle.com/en/java/javase/19/jshell/snippets.html), JShell will display an error message while attempting to use malformed overwritten variables, methods and classes. For example:
$ jshell
| Welcome to JShell -- Version 19.0.1
| For an introduction type: /help intro
jshell> int foo = 42;
foo ==> 42
jshell> int getFoo() { return foo;}
| created method getFoo()
jshell> double foo = 42.0
foo ==> 42.0
jshell> getFoo()
| attempted to call method getFoo() which cannot be invoked until this error is corrected:
| incompatible types: possible lossy conversion from double to int
| int getFoo() { return foo;}
| ^-^
However, errors about overriding and hierarchy are not displayed by default, but instead display a "cannot find symbol" error. These include:
a) A method is overridden by a method with incompatible return type
b) Interfaces appear in `extends` clause
c) A class appears in `implements` clause
d) A subclass of an abstract class does not override abstract methods
e) @Override is annotated on a method that does not override
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run jshell without any options, and input code shown in "Source Code" section.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
For example, for the last line in case a, it should display a message like:
| attempted to reference class Bar which cannot be referenced until this error is corrected:
| method() in Bar cannot override method() in Foo
| return type void is not compatible with int
| void method() {}
| ^--------------^
ACTUAL -
For the last line in all cases, it displays:
| Error:
| cannot find symbol
| symbol: class Bar
| new Bar()
| ^-^
---------- BEGIN SOURCE ----------
// Case a:
class Foo {
void method() {}
}
class Bar extends Foo {
void method() {}
}
class Foo {
int method() { return 0; }
}
new Bar() // This line should display "cannot be referenced until this error is corrected" message
// Case b:
class Foo {}
class Bar extends Foo {}
interface Foo {}
new Bar() // This line should display "cannot be referenced until this error is corrected" message
// Case c:
interface Foo {}
class Bar implements Foo {}
class Foo {}
new Bar() // This line should display "cannot be referenced until this error is corrected" message
// Case d:
class Foo {
void method() {}
}
class Bar extends Foo {}
abstract class Foo {
abstract void method();
}
new Bar() // This line should display "cannot be referenced until this error is corrected" message
// Case e:
class Foo {
void method() {}
}
class Bar extends Foo {
@Override void method() {}
}
class Foo {}
new Bar() // This line should display "cannot be referenced until this error is corrected" message
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Add -v option (it displays the error message only when you make subclasses malformed)
FREQUENCY : always