-
Notifications
You must be signed in to change notification settings - Fork 9.1k
MAPREDUCE-7251: Present friendlier error for non-static main #1751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a unit test to make sure we trigger this instead of NPE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a test, but I couldn't get Hadoop to run locally—seeing this error:
Plugin org.apache.hadoop:hadoop-maven-plugins:3.3.0-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact org.apache.hadoop:hadoop-maven-plugins:jar:3.3.0-SNAPSHOT
Guidance from the Dev Environment Setup was no help unfortunately. The suggested docker script also fails to build.
💔 -1 overall
This message was automatically generated. |
- When executing a jar with RunJar, first check whether the method is static and if not throw an error. This prevents a cryptic NullPointerException from being raised within Method.invoke's implementation
💔 -1 overall
This message was automatically generated. |
package org.apache.hadoop.util; | ||
|
||
public class NonStaticMain { | ||
public void main(String[] args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must have a spaces checkstyle warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are you seeing a checkstyle warning?
when(runJar.getSystemClasses()).thenReturn(systemClasses); | ||
|
||
// create the test jar | ||
File testJar = JarFinder.makeClassLoaderTestJar(this.getClass(), TEST_ROOT_DIR, TEST_JAR_2_NAME, BUFF_SIZE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80 chars?
File testJar = JarFinder.makeClassLoaderTestJar(this.getClass(), TEST_ROOT_DIR, TEST_JAR_2_NAME, BUFF_SIZE, | ||
mainCls); | ||
// form the args | ||
String[] args = new String[3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is with [2]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took this from testClientClassLoader
.
|
||
// run RunJar | ||
try { | ||
runJar.run(args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use LambaTestUtils#intercept
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this doesn't work because run
throws Throwable
not Exception
and so it doesn't map to the Callable
interface cleanly.
💔 -1 overall
This message was automatically generated. |
- Since RunJar#run throws Throwable, it doesn't wrap cleanly with Callable, which throws Exception. This is because IOException subclasses Throwable. Since LambdaTestUtils#intercept expects a Callable, it can't be used.
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
My new test is passing—seems like there are some flaky
|
💔 -1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
@goiri do you mind taking another look? |
When executing a jar with
RunJar
, first check whether the method is static and if not throw an error. This prevents a crypticNullPointerException
from being raised withinMethod.invoke
's implementation.See: MAPREDUCE-7251