SonarQube Runner在分析期间抛出NullPointerException

时间:2015-01-29 13:55:04

标签: nullpointerexception sonarqube runner

更新: 我在Fedora 21上运行它。 SonarQube - 5.0。 SonarQube Runner - 2.4

UPDATE2:Findbugs v3.1,Java插件v2.8

UPDATE3: 分析器在以下文件中失败:

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MyManager extends ParentManager {
    public MyManager(int id, int var1, int var2, int var3) {
        super(id, var1, var2, var3);
    }

    public void load() {
        Connection con = null;
        Statement st;
        ResultSet res;

        try {

            con = DatabaseManager.getDataSource().getConnection();
            st = con.createStatement();

            int currentId = 0;
            CurrentData currentData= null;

            res = st.executeQuery("SELECT subjects.subjectname" + " AS name, " +
                    " subjects.subjectcode AS code, " +
                    " groups.groupname AS gname, " +
                    " groups.groupID AS gID , " +
                    " subjects.sID AS sID, " +
                    " groups.isMain AS ismain   " +
                    " FROM joinGroup LEFT JOIN groups ON joinGroup.groupID=groups.groupID " +
                    " LEFT JOIN subjects ON subjects.sID=groups.sID " +
                    " WHERE joinGroup.sID=" + id + "  " +
                    " AND groups.var1" + var1 + " AND groups.var2=" + var2 + " " +
                    " ORDER BY name, subjects.subjectcode, subjects.sID ");
            while (res.next()) {
                if (currentId != res.getInt("sID")) {
                    currentData = new CurrentData();
                    data.subjects.add(currentData);
                    currentData.subjectName = res.getString("name");
                    currentData.subjectID = res.getInt("sID");
                }
                CurrentGroupData groupData = new CurrentGroupData();
                groupData.name = res.getString("gname");
                groupData.id = res.getInt("gID");
                currentId = res.getInt("sID");
                if (res.getBoolean("ismain")) {
                    assert currentData != null;
                    currentData.groupID = res.getInt("gID");
                }
                if (currentData != null) {
                    currentData.groups.add(groupData);
                }
            }

            loadSubjectsData(st, res);

        } catch (Exception exc) {
            Log.writeLog(ex);
        } finally {
            try {
                con.close();
            } catch (SQLException e) {
                Log.writeLog(e);
            }
        }
    }
}

我按照声纳网站上的教程安装了SonarQube。 我可以浏览到localhost:9000并显示起始页面。 然后我尝试通过命令分析项目:sonar-runner。 它失败。 运行sonar-runner -X会显示以下内容:

  

>   错误:Sonar跑步者执行期间出错   org.sonar.runner.impl.RunnerException:无法执行Sonar       在org.sonar.runner.impl.BatchLauncher $ 1.delegateExecution(BatchLauncher.java:91)       在org.sonar.runner.impl.BatchLauncher $ 1.run(BatchLauncher.java:75)       at java.security.AccessController.doPrivileged(Native Method)       在org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)       在org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)       在org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)       在org.sonar.runner.api.Runner.execute(Runner.java:100)       在org.sonar.runner.Main.executeTask(Main.java:70)       在org.sonar.runner.Main.execute(Main.java:59)       在org.sonar.runner.Main.main(Main.java:53)   引起:org.sonar.squidbridge.api.AnalysisException:SonarQube无法分析文件:' /path/to/my/file/MyFile.java'       在org.sonar.java.ast.AstScanner.simpleScan(AstScanner.java:114)       在org.sonar.java.ast.AstScanner.scan(AstScanner.java:75)       在org.sonar.java.JavaSquid.scanSources(JavaSquid.java:122)       在org.sonar.java.JavaSquid.scan(JavaSquid.java:115)       at org.sonar.plugins.java.JavaSquidSensor.analyse(JavaSquidSensor.java:91)       在org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:79)       在org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:70)       在org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:122)       在org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:222)       at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)       在org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)       在org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:235)       在org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:230)       在org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:223)       at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)       在org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)       在org.sonar.batch.scan.ScanTask.scan(ScanTask.java:65)       在org.sonar.batch.scan.ScanTask.execute(ScanTask.java:52)       在org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:128)       at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)       在org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)       在org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:171)       在org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)       在org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)       在org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:606)       在org.sonar.runner.impl.BatchLauncher $ 1.delegateExecution(BatchLauncher.java:87)       ......还有9个   引起:java.lang.NullPointerException       at org.sonar.java.checks.AbstractInjectionChecker.isIdentifierDynamicString(AbstractInjectionChecker.java:67)       在org.sonar.java.checks.AbstractInjectionChecker.isDynamicString(AbstractInjectionChecker.java:54)       在org.sonar.java.checks.AbstractInjectionChecker.isDynamicString(AbstractInjectionChecker.java:49)       在org.sonar.java.checks.AbstractInjectionChecker.isDynamicString(AbstractInjectionChecker.java:57)       在org.sonar.java.checks.AbstractInjectionChecker.isDynamicString(AbstractInjectionChecker.java:49)       在org.sonar.java.checks.AbstractInjectionChecker.isDynamicString(AbstractInjectionChecker.java:57)       在org.sonar.java.checks.AbstractInjectionChecker.isDynamicString(AbstractInjectionChecker.java:49)       在org.sonar.java.checks.AbstractInjectionChecker.isDynamicString(AbstractInjectionChecker.java:57)       在org.sonar.java.checks.SQLInjectionCheck.visitNode(SQLInjectionCheck.java:48)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:95)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:113)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:113)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:113)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:113)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:113)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:113)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:113)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:113)       在org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)       在org.sonar.java.ast.visitors.SubscriptionVisitor.scanTree(SubscriptionVisitor.java:73)       在org.sonar.java.ast.visitors.SubscriptionVisitor.scanFile(SubscriptionVisitor.java:67)       在org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:122)       在com.sonar.sslr.impl.ast.AstWalker.walkAndVisit(AstWalker.java:67)       在org.sonar.java.ast.AstScanner.simpleScan(AstScanner.java:107)       ......还有38个   >

没有做任何事情"异国情调",只是按照这样的官方教程: http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Runner

我在本地运行它。 有什么想法吗?

由于

2 个答案:

答案 0 :(得分:3)

我遇到了类似ReturnEmptyArrayyNotNullCheck的问题。作为一种解决方法,我在sonarqube web gui中禁用了该规则。 以管理员身份登录。单击顶部菜单中的“规则”。搜索SQL或Inject或其他任何单词以查找您认为导致分析失败的规则。然后选择规则并在附加到项目的质量配置文件中禁用它。当然,所有附加项目都会忽略这条规则。

答案 1 :(得分:-1)

我没有解决方案,但遇到了同样的问题,并在声纳网站上找到了这个参考,你可能遇到同样的问题吗?

http://sonarqube.15.x6.nabble.com/NullPointerException-analysing-file-with-SQLInjectionCheck-td5032155.html(滚动到最后)