OutOfMemory - Sonar 无法分析项目源代码,也找不到问题

OutOfMemory - Sonar fails to analyse project source code, and it can't find issues

我是 运行 插件 SonarLint,在 IntelliJ Idea 的 Java 项目中。

当我请求对整个项目进行代码分析时,我收到以下消息:

SonarLint 分析失败:Java 堆 space

这是日志:

Error running SonarLint analysis
java.lang.OutOfMemoryError: Java heap space



java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:3181)
    at java.util.Vector.grow(Vector.java:266)
    at java.util.Vector.ensureCapacityHelper(Vector.java:246)
    at java.util.Vector.addElement(Vector.java:620)
    at com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.addNode(DOM2DTM.java:247)
    at com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.nextNode(DOM2DTM.java:543)
    at com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase._nextsib(DTMDefaultBase.java:567)
    at com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase.getNextSibling(DTMDefaultBase.java:1142)
    at com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBaseTraversers$ChildTraverser.next(DTMDefaultBaseTraversers.java:465)
    at com.sun.org.apache.xpath.internal.axes.AxesWalker.getNextNode(AxesWalker.java:337)
    at com.sun.org.apache.xpath.internal.axes.AxesWalker.nextNode(AxesWalker.java:365)
    at com.sun.org.apache.xpath.internal.axes.WalkingIterator.nextNode(WalkingIterator.java:197)
    at com.sun.org.apache.xpath.internal.axes.NodeSequence.nextNode(NodeSequence.java:344)
    at com.sun.org.apache.xpath.internal.axes.NodeSequence.runTo(NodeSequence.java:503)
    at com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList.<init>(DTMNodeList.java:83)
    at com.sun.org.apache.xpath.internal.objects.XNodeSet.nodelist(XNodeSet.java:348)
    at com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.getResultAsType(XPathExpressionImpl.java:364)
    at com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:110)
    at com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:191)
    at org.sonar.java.xml.XmlCheckContextImpl.evaluate(XmlCheckContextImpl.java:82)
    at org.sonar.java.xml.XmlCheckContextImpl.evaluateOnDocument(XmlCheckContextImpl.java:76)
    at org.sonar.java.checks.xml.spring.SingleConnectionFactoryCheck.scanFileWithXPathExpressions(SingleConnectionFactoryCheck.java:45)
    at org.sonar.java.xml.XPathXmlCheck.scanFile(XPathXmlCheck.java:36)
    at org.sonar.java.xml.XmlAnalyzer.simpleScanAsXmlFile(XmlAnalyzer.java:107)
    at org.sonar.java.xml.XmlAnalyzer.simpleScan(XmlAnalyzer.java:97)
    at org.sonar.java.xml.XmlAnalyzer.scan(XmlAnalyzer.java:81)
    at org.sonar.plugins.java.XmlFileSensor.execute(XmlFileSensor.java:55)
    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:142)
    at org.sonarsource.sonarlint.core.container.ComponentContainer.startComponents(ComponentContainer.java:125)

如何增加内存?

Eclipse: Run --> Run Configurations --> 然后 select maven build 下的项目 --> 然后 select 选项卡 "JRE" --> 然后输入 -Xmx1024m.

Run --> Run Configurations --> select "JRE" 选项卡 --> 然后输入 -Xmx1024m

我建议你使用 profiler 来检查你需要多少内存,这样你就不会分配太多。

我错过了 IntelliJ Idea:

您可以获取信息here

请确保您在正确的位置增加了堆。您需要单击 IDEA 的 Ant 工具 window 中的 'Properties' 按钮并在那里编辑 'Maximum heap size (Mb)' 字段。