gpt4 book ai didi

java - Sonar 管 5.6 : violations reported for an outer class by findbugs is not reported as a sonar violation

转载 作者:行者123 更新时间:2023-11-29 04:41:52 28 4
gpt4 key购买 nike

我正在使用带有 java 插件 4.0 和 findbugs 插件 3.4.3 的 SonarQube 5.6。使用此配置,findbugs 报告的外部类违规不会被报告为 Sonar 违规。以下是代码详情。

Java文件

package com.test.pkg;

import java.net.MalformedURLException;
import java.net.URL;

public class URLTest {

public static void main (String [] args) {
// do nothing
}
}

class OuterURL {

public void foo () throws MalformedURLException {
URL findbugsURL1 = new URL ("http://findbugs.sourceforge.net/");
URL findbugsURL2 = new URL ("http://findbugs.sourceforge.net/");
if (findbugsURL1.equals(findbugsURL2)) {
System.out.println("both urls are equal");
}
}

}

Findbugs-results.xml 包含以下内容

<BugCollection version="3.0.1" sequence="0" timestamp="1470131475000" analysisTimestamp="1470133581561" release="">
<Project>
<Jar><somepath>/project1/bin/com/test/pkg/OuterURL.class</Jar>
<Jar><somepath>/project1/bin/com/test/pkg/URLTest.class</Jar>
<AuxClasspathEntry><somepath>/project1/bin</AuxClasspathEntry>
<AuxClasspathEntry><somepath>/project1/src/.sonar/findbugs/annotations.jar</AuxClasspathEntry>
<AuxClasspathEntry><somepath>/project1/src/.sonar/findbugs/jsr305.jar</AuxClasspathEntry>
<WrkDir><somepath>/project1/src/.sonar</WrkDir>
</Project>
<BugInstance type="DMI_BLOCKING_METHODS_ON_URL" priority="1" rank="16" abbrev="Dm" category="PERFORMANCE" instanceHash="3c28cb79b988fda6b10e89974603edc7" instanceOccurrenceNum="0" instanceOccurrenceMax="0">
<ShortMessage>The equals and hashCode methods of URL are blocking</ShortMessage>
<LongMessage>Invocation of java.net.URL.equals(Object), which blocks to do domain name resolution, in com.test.pkg.OuterURL.foo()</LongMessage>
<Class classname="com.test.pkg.OuterURL" primary="true">
<SourceLine classname="com.test.pkg.OuterURL" start="13" end="21" sourcefile="URLTest.java" sourcepath="com/test/pkg/URLTest.java">
<Message>At URLTest.java:[lines 13-21]</Message>
</SourceLine>
<Message>In class com.test.pkg.OuterURL</Message>
</Class>
<Method classname="com.test.pkg.OuterURL" name="foo" signature="()V" isStatic="false" primary="true">
<SourceLine classname="com.test.pkg.OuterURL" start="16" end="21" startBytecode="0" endBytecode="131" sourcefile="URLTest.java" sourcepath="com/test/pkg/URLTest.java"/>
<Message>In method com.test.pkg.OuterURL.foo()</Message>
</Method>
<Method classname="java.net.URL" name="equals" signature="(Ljava/lang/Object;)Z" isStatic="false" role="METHOD_CALLED">
<SourceLine classname="java.net.URL" start="866" end="870" startBytecode="0" endBytecode="68" sourcefile="URL.java" sourcepath="java/net/URL.java"/>
<Message>Called method java.net.URL.equals(Object)</Message>
</Method>
<SourceLine classname="com.test.pkg.OuterURL" primary="true" start="18" end="18" startBytecode="22" endBytecode="22" sourcefile="URLTest.java" sourcepath="com/test/pkg/URLTest.java">
<Message>At URLTest.java:[line 18]</Message>
</SourceLine>

在控制台日志中,我可以看到以下消息。警告:“com.test.pkg.OuterURL”类无法与其原始源文件匹配。它可能是一个动态生成的类。

这个问题似乎是由于 ByteCodeResourceLocator 的 findJavaClassFile 方法中的逻辑而发生的

有没有人见过类似的问题?

最佳答案

这是 sonar-findbugs 插件的问题。找不到原始源文件。

后续解决请引用这个issue: https://github.com/SonarQubeCommunity/sonar-findbugs/issues/40

关于java - Sonar 管 5.6 : violations reported for an outer class by findbugs is not reported as a sonar violation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38882123/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com