带有SonarLint的Eclipse与OutOfMemory崩溃,处理特定的有问题的类

时间:2018-05-15 07:33:30

标签: eclipse jvm sonarlint

我在Windows 7上使用eclipse,在an answer建议使用SonarLint捕获有问题的代码之后,我安装了它并且工作正常(99%)。

我现在遇到了具有太多声纳问题的特定遗留类的问题(10K行错误代码)。

Eclipse在处理这些文件时会一直崩溃,日志中出现OutOfMemoryError异常:

!ENTRY org.eclipse.osgi 4 0 2018-05-14 15:10:40.524
!MESSAGE Application error
!STACK 1
java.lang.OutOfMemoryError: Java heap space

!ENTRY org.eclipse.core.jobs 4 2 2018-05-14 15:10:40.526
!MESSAGE An internal error occurred during: "SonarLint analysis of file MyJava.java".
!STACK 0
java.lang.OutOfMemoryError: Java heap space

!ENTRY org.eclipse.e4.ui.workbench 4 0 2018-05-14 15:10:51.220
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.eclipse.e4.core.di.InjectionException: org.eclipse.swt.SWTException: Invalid thread access
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:65)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:966)
    at org.eclipse.e4.core.internal.di.InjectorImpl.disposed(InjectorImpl.java:426)
    at org.eclipse.e4.core.internal.di.Requestor.disposed(Requestor.java:154)
    at org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:78)
    at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:111)
    at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.handleInvalid(TrackableComputationExt.java:74)
    at org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:176)
    at org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:161)
    at org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.dispose(EclipseContextOSGi.java:106)
    at org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.bundleChanged(EclipseContextOSGi.java:139)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:903)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:213)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:120)
    at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:112)
    at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:156)
    at org.eclipse.osgi.container.Module.publishEvent(Module.java:476)
    at org.eclipse.osgi.container.Module.doStop(Module.java:634)
    at org.eclipse.osgi.container.Module.stop(Module.java:498)
    at org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:202)
    at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:165)
    at java.lang.Thread.run(Unknown Source)

我没有办法在sonarlint插件中排除文件。

有没有办法继续使用SonarLint并处理这些文件,还是有不同的方法/插件?

我尝试添加-XX:+UseCompressedOops,但没有帮助。另一种配置:

-Xms512m
-Xmx1024m

1 个答案:

答案 0 :(得分:1)

你的方向正确。我们还有Uber文件,在我们的项目/ CR中包含超过10K行代码。

我们的解决方案很简单 - 将JVM最大堆大小增加到4GB:

-Xms512m
-Xmx4096m

这解决了13K错误代码文件的问题,这是我们最终导致java.lang.OutOfMemoryError异常的原因(使用Eclipse Oxygen)。

交替解决方案?您可以configure SonarLint not to scan automatically在编辑器中打开的每个Java类。这样,您可以手动选择扫描并避免大文件扫描。

我建议将堆大小增加到4GB,然后我的工作站再次增加16GB内存。