声纳演示StaticMembersAccessCheck无法验证文件中的代码

时间:2018-11-26 03:25:13

标签: sonarqube

声纳演示StaticStaticMembersAccessCheck.java可以找到不兼容的内容:

Demo.java:

class A {
    public static int counter = 0;
    public int nonStaticCounter = 0;
    public C c = new C();
    public D d = new D();
    public class C {
        public int counter = 0;
        public D d = new D();
    }
    public static class D {
        public static int counter = 0;
        public static class E {
            public static int counter = 0;
        }
    }
}

class B {
    private A first = new A();
    private A second = new A();
    private A.D third = new A.D();
    public void noncompliant() {
        first.counter ++; // Noncompliant 
    }

    public void compliant() {
          A.counter ++;
          first.nonStaticCounter ++;
    }  
}

但是当我在另一个文件中定义A类时,它就会失败。

A.java:

class A {
    public static int counter = 0;
    public int nonStaticCounter = 0;
    public C c = new C();
    public D d = new D();
    public class C {
        public int counter = 0;
        public D d = new D();
    }
    public static class D {
        public static int counter = 0;
        public static class E {
            public static int counter = 0;
        }
    }
}

Demo.java:

import A;
class B {
    private A first = new A();
    private A second = new A();
    private A.D third = new A.D();
    public void noncompliant() {
        first.counter ++; // Noncompliant 
    }

    public void compliant() {
          A.counter ++;
          first.nonStaticCounter ++;
    }  
}

sonar cannot get class info when the class was defined in another file.

如何解决这个问题?

0 个答案:

没有答案