-
Notifications
You must be signed in to change notification settings - Fork 145
JDK-8230119: NullPointerException if Application subclass has non-static main(String[]) method #570
Comments
In this case we shouldn't throw an exception, but we should ignore that main method and launch the |
My assumption was that a non-static main method in an |
I agree. Maybe a warning should be emitted. |
That's a fair point about emitting a warning, since it is likely a mistake. Similarly, if the main method is not One thing to point out, which might help inform what we want to do here, is that during the review of the launcher test changes needed as part of decoupling of JavaFX from the JDK, the JDK team raised the question of whether the Java launcher support for launching JavaFX Application classes without a main method should be deprecated and removed in a future version. If that is the route we end up going, then a |
I agree a warning seems the best option. Also, if the launching-without-main-method functionality does get deprecated then a warning should be emitted if the main-class is missing the |
Yes, something along those lines was exactly my thinking.
It only stayed in because I successfully argued that it would be too disruptive to remove it with no warning and potentially break existing applications. This reminds me that I was supposed to file an RFE to deprecate and then remove it, but haven't done so yet. |
I filed JDK-8230119 in JBS to track this. |
Worth noting is that a non-public |
When using the below as a main-class:
The following exception is thrown:
Which is caused by
LauncherImpl
callingmainMethod.invoke(null, new Object[]{args})
, which is just assuming themain
method it found isstatic
.While I doubt such a situation arises often, it came up recently in a question on Stack Overflow. The issue here is the error message does not make the cause obvious. It'd be beneficial if
LauncherImpl
checked whether or not the method isstatic
and, if it's not, throw a more detailed exception. For example:The text was updated successfully, but these errors were encountered: