Sonar error with API incompatibility for Absent Code attribute

One of my fellow developers created a new app the other day and now I can't get a good sonar collector. I've tried a number of documented workarounds / solutions for this type of no-code error but couldn't find the right combination. The project includes glass panes and jars embedded in a glass jar, which should provide an implementation for javax servlets. They are configured to scan the area.

<dependency>
    <groupId>org.glassfish.main.extras</groupId>
    <artifactId>glassfish-embedded-all</artifactId>
    <version>4.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.servlet</artifactId>
    <version>3.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <scope>provided</scope>
</dependency>

      

I tried this option too:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <classpathDependencyExcludes>
            <!-- exclude code absent api -->                                    
            <classpathDependencyExclude>javax:javaee-api</classpathDependencyExclude>                                
            <classpathDependencyExclude>javax:javaee-web-api</classpathDependencyExclude>
        </classpathDependencyExcludes>
    </configuration>
</plugin>

      

This is a bug since Maven 3.0.4:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar (default-cli) on project Filters: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/http/HttpServletRequestWrapper
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/root/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.0.2/sonar-maven-plugin-3.0.2.jar
[ERROR] urls[1] = file:/root/.m2/repository/org/apache/maven/shared/maven-dependency-tree/2.2/maven-dependency-tree-2.2.jar
[ERROR] urls[2] = file:/root/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[3] = file:/root/.m2/repository/org/eclipse/aether/aether-util/0.9.0.M2/aether-util-0.9.0.M2.jar
[ERROR] urls[4] = file:/root/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[ERROR] urls[5] = file:/root/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[6] = file:/root/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar
[ERROR] urls[7] = file:/root/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.6/sonar-scanner-api-2.6.jar
[ERROR] urls[8] = file:/root/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
[ERROR] urls[9] = file:/root/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar
[ERROR] urls[10] = file:/root/.m2/repository/com/google/code/findbugs/jsr305/2.0.3/jsr305-2.0.3.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[project>com.avaya.zephyr.services.sample_services.Authorization:Filters:3.4.0.0.0-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]

      

The pom project looks basically like another similar project that has no bug. However, it does have a warning:

Apr 20, 2017 4:52:16 PM net.sourceforge.pmd.lang.java.typeresolution.ClassTypeResolver visit
WARNING: Could not find class myBetterClass, due to: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ws/rs/core/Application

      

I thought that providing a built-in glass fish jar should have solved this problem. (Maybe a new version of the glass fish is needed?)

+3


source to share


1 answer


You can try to fix this problem by following these steps:



  • Upgrade Maven 3.5.0

    to support Maven to the latest version.

  • You can follow here to see if your version is compatible with it or not. From the logs, your build is using an older version of the plugin

    .scanner.maven: sonar-maven-plugin: 3.0.2

    Try to run

    mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar
    
          

  • Make sure your exceptions are marked in your <properties>

    pom.xml file as

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <sonar.host.url>http://www.example.com/</sonar.host.url>
        <sonar.exclusions>some/path/to/javax/javaee-api/**, some/path/to/javax:javaee-web-api</sonar.exclusions>
    </properties>
    
          

+2


source







All Articles