Review Request: JDK-8174694: improve error message shown when main class can't be loaded

Alan Bateman Alan.Bateman at oracle.com
Wed Feb 15 18:39:03 UTC 2017


On 15/02/2017 17:21, Vicente Romero wrote:

> The simplest reproductor for this issue is:
>
> ------------------------------------------------------------------------------------------------ 
>
> public class A extends B {
>     public static void main(String... args) {}
> }
> ------------------------------------------------------------------------------------------------ 
>
> class B {}
> ------------------------------------------------------------------------------------------------ 
>
>
> $javac -d out A.java B.java
> $rm out/B.class
>
> before this patch this command:
> $java -cp out A
>
> produces this output
> Error: Could not find or load main class A
>
> with the current patch, the output produced is:
> Error: Could not find or load main class A
> because class B is not defined.
>
> if while loading the main class ClassNotFoundException is produced 
> then the second part of the message will be: "because class Foo is not 
> defined."
> if NoClassDefFoundError is produced then it will be: "because class 
> Foo is not defined"
It's good that "B" is shown in the output but "because class B is not 
defined" looks very strange to me. Have you consider something more 
useful like:

Error: Could not find or load main class A
Caused by: java.lang.NoClassDefFoundError: B

-Alan




More information about the core-libs-dev mailing list