I am writing a special Sonarqube Java rule, but I continue this error when I try to parse my code:
"SonarQube cannot parse file. File Path" org.sonar.java.resolve.JavaSymbol $ TypeJavaSymbol cannot be dropped org.sonar.java.resolve.JavaSymbol $ TypeJavaSymbol "
As you can see, the source type and cast type have the same qualified name. Therefore, I assume that this could only be a problem with ClassLoader shading.
Here you can find all the open source code:
https://github.com/oasp-forge/sonarqube-devon-plugin (if you want to check the POM class or rules).
Here is the rule code causing the problem:
package io.oasp.ide.sonarqube.common.impl;
import io.oasp.module.basic.common.api.reflect.OaspPackage;
@Rule(key = "ArchitecturePackageCheck", name = "My Package Check", description = "Verify that the code is following My package conventions.",
priority = Priority.MAJOR, tags = { "bug" })
public class ArchitecturePackageCheck extends BaseTreeVisitor implements JavaFileScanner {
private List<String> issues;
private String fullyQualifiedName;
public DevonArchitecturePackageCheck() {
super();
this.issues = new ArrayList<>();
}
public String getFullyQualifiedName() {
return this.fullyQualifiedName;
}
@Override
public void scanFile(JavaFileScannerContext context) {
this.issues.clear();
scan(context.getTree());
for (String issue : this.issues) {
int lineNumber = 1;
context.addIssue(lineNumber, this, issue);
}
}
@Override
public void visitIdentifier(IdentifierTree tree) {
super.visitIdentifier(tree);
}
@Override
public void visitClass(ClassTree tree) {
this.fullyQualifiedName = ((JavaSymbol.TypeJavaSymbol) tree.symbol()).getFullyQualifiedName();
String packageName = " ";
int lastDot = this.fullyQualifiedName.lastIndexOf('.');
if (lastDot > 0) {
packageName = this.fullyQualifiedName.substring(0, lastDot);
}
if (packageName.isEmpty()) {
this.issues.add("Invalid Package IS EMPTY!" + packageName + " !");
} else {
OaspPackage pkg = OaspPackage.of(packageName);
if (!pkg.isValid()) {
this.issues.add("Invalid Package IS VALID" + packageName + " !");
}
}
}
}
source
share