首页 > 解决方案 > 带有 SonarLint 的 Eclipse 崩溃,OutOfMemory 处理特定的有问题的类

问题描述

我在 Windows 7 上使用 Eclipse,在回答建议 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

标签: eclipsejvmsonarlint

解决方案


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

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

-Xms512m
-Xmx4096m

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

替代解决方案?您可以将 SonarLint 配置为不自动扫描您在编辑器中打开的每个 Java 类。这样,您可以手动选择扫描并避免大文件扫描。

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


推荐阅读