NullPointerException when running JUnit test in Eclipse IDE

Problem

JUnit test cases cannot be run in Eclipse IDE with below errors

!ENTRY org.eclipse.core.jobs 4 2 2017-07-05 12:05:37.873
!MESSAGE An internal error occurred during: "Launching ClarityUtilTest (1)".
!STACK 0
java.lang.NullPointerException
	at java.util.zip.ZipFile.getZipEntry(Unknown Source)
	at java.util.zip.ZipFile.access$900(Unknown Source)
	at java.util.zip.ZipFile$ZipEntryIterator.next(Unknown Source)
	at java.util.zip.ZipFile$ZipEntryIterator.nextElement(Unknown Source)
	at java.util.zip.ZipFile$ZipEntryIterator.nextElement(Unknown Source)
	at org.eclipse.m2e.jdt.internal.BuildPathManager.getJavaDocPathInArchive(BuildPathManager.java:696)
	at org.eclipse.m2e.jdt.internal.BuildPathManager.getJavaDocUrl(BuildPathManager.java:681)
	at org.eclipse.m2e.jdt.internal.BuildPathManager.getJavaDocUrl(BuildPathManager.java:674)
	at org.eclipse.m2e.jdt.internal.BuildPathManager.configureAttachedSourcesAndJavadoc(BuildPathManager.java:309)
	at org.eclipse.m2e.jdt.internal.BuildPathManager.getClasspath(BuildPathManager.java:258)
	at org.eclipse.m2e.jdt.internal.BuildPathManager.getClasspath(BuildPathManager.java:367)
	at org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider.addMavenClasspathEntries(MavenRuntimeClasspathProvider.java:155)
	at org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider.resolveClasspath0(MavenRuntimeClasspathProvider.java:126)
	at org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider$1.call(MavenRuntimeClasspathProvider.java:114)
	at org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider$1.call(MavenRuntimeClasspathProvider.java:1)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99)
	at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1355)
	at org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider.resolveClasspath(MavenRuntimeClasspathProvider.java:111)
	at org.eclipse.jdt.internal.launching.RuntimeClasspathProvider.resolveClasspath(RuntimeClasspathProvider.java:65)
	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1260)
	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:412)
	at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate.getClasspath(JUnitLaunchConfigurationDelegate.java:366)
	at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate.launch(JUnitLaunchConfigurationDelegate.java:147)
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)

Cause

The project is bundled with Maven and using the libraries downloaded by Maven. When running JUnit, it try to locate the javadoc. Somehow the javadoc is not accessible or cannot be found. In Eclipse Java Project, the reference can be found in .classpath file
<classpathentry kind="var" path="M2_REPO/junit/junit/4.12/junit-4.12.jar" sourcepath="M2_REPO/junit/junit/4.12/junit-4.12-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Users/bzhan08/.m2/repository/junit/junit/4.12/junit-4.12-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>

Solution

Remove the lines of javadoc from .classpath

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.