Exception when exists empty jar in projects

java
sonarlint

(ori marko) #1

I’m using Sonar plugin to Eclipse in Java projects,
Some repositories have an empty jar in projects as resource, for example in https://github.com/jmetertea/jmeter-plugins-manager.

This create a recurring (every scan refresh) exception in sonar:

Error during execution of SonarLint analysis
java.lang.IllegalStateException: Can not create ClassLoader
	at org.sonar.java.bytecode.ClassLoaderBuilder.create(ClassLoaderBuilder.java:60)
	at org.sonar.java.model.VisitorsBridge.<init>(VisitorsBridge.java:92)
	at org.sonar.java.JavaSquid.createVisitorBridge(JavaSquid.java:103)
	at org.sonar.java.JavaSquid.<init>(JavaSquid.java:93)
	at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:92)
	at org.sonarsource.sonarlint.core.analyzer.sensor.NewSensorsExecutor.executeSensor(NewSensorsExecutor.java:72)
	at org.sonarsource.sonarlint.core.analyzer.sensor.NewSensorsExecutor.execute(NewSensorsExecutor.java:63)
	at org.sonarsource.sonarlint.core.analyzer.sensor.PhaseExecutor.execute(PhaseExecutor.java:36)
	at org.sonarsource.sonarlint.core.container.analysis.AnalysisContainer.doAfterStart(AnalysisContainer.java:141)
	at org.sonarsource.sonarlint.core.container.ComponentContainer.startComponents(ComponentContainer.java:125)
	at org.sonarsource.sonarlint.core.container.ComponentContainer.execute(ComponentContainer.java:110)
	at org.sonarsource.sonarlint.core.container.standalone.StandaloneGlobalContainer.analyze(StandaloneGlobalContainer.java:141)
	at org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl.analyze(StandaloneSonarLintEngineImpl.java:89)
	at org.sonarlint.eclipse.core.internal.jobs.StandaloneSonarLintClientFacade.runAnalysis(StandaloneSonarLintClientFacade.java:76)
	at org.sonarlint.eclipse.core.internal.jobs.AnalyzeProjectJob.run(AnalyzeProjectJob.java:456)
	at org.sonarlint.eclipse.core.internal.jobs.AnalyzeProjectJob.runAnalysisAndUpdateMarkers(AnalyzeProjectJob.java:204)
	at org.sonarlint.eclipse.core.internal.jobs.AnalyzeProjectJob.doRun(AnalyzeProjectJob.java:160)
	at org.sonarlint.eclipse.core.internal.jobs.AbstractSonarProjectJob.runInWorkspace(AbstractSonarProjectJob.java:43)
	at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:39)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.IllegalStateException: Unable to open C:\jmeter-plugins-manager-master\src\test\resources\dummy.jar
	at org.sonar.java.bytecode.loader.JarLoader.<init>(JarLoader.java:51)
	at org.sonar.java.bytecode.loader.SquidClassLoader.<init>(SquidClassLoader.java:59)
	at org.sonar.java.bytecode.ClassLoaderBuilder.create(ClassLoaderBuilder.java:58)
	... 19 more
Caused by: java.util.zip.ZipException: zip file is empty
	at java.util.zip.ZipFile.open(Native Method)
	at java.util.zip.ZipFile.<init>(ZipFile.java:225)
	at java.util.zip.ZipFile.<init>(ZipFile.java:155)
	at java.util.jar.JarFile.<init>(JarFile.java:166)
	at java.util.jar.JarFile.<init>(JarFile.java:130)
	at org.sonar.java.bytecode.loader.JarLoader.<init>(JarLoader.java:48)
	... 21 more

(Nicolas Peru) #2

Thanks for the feedback !
This is indeed an issue on SonarJava side : I created a ticket to fix it : https://jira.sonarsource.com/browse/SONARJAVA-2914

We should just skip an empty file and not create a jar loader for it.