3

One of my fellow developers created a new application the other day and now I can't get a good Sonar compile. I've tried a number of documented workarounds/solutions to this sort of Absent Code error, but haven't found the right combination. The project includes the glassfish and glassfish-embedded-all jars that are supposed to provide an implementation for the javax-servlet. They are set to scope test.

<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 one too with no luck:

<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 the error with 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 project's pom looks mostly like another similar project that isn't having the error. It does, however, 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 the glassfish embedded jar was supposed to solve that sort of issue. (Maybe there is a newer version of glassfish needed?)

Naman
  • 27,789
  • 26
  • 218
  • 353
Sinc
  • 553
  • 1
  • 8
  • 31
  • Can you run with mvn -X and show the complete output? And are by any chance still running Java 6? – fhossfel Oct 01 '17 at 21:47
  • Have you seen this: https://issues.apache.org/jira/browse/MNG-5787? But 3.0.4 should actually not be affected. – fhossfel Oct 01 '17 at 21:50

1 Answers1

2

You can try to resolve this by trying out the following:

  1. Update Maven to 3.5.0 to maintain the Maven to its latest version.

  2. You can follow the matrix here to see if the version used by you is compatible or not. From the logs, your build is using an older version of the plugin

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

    Try executing

    mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar
    
  3. Make sure your exclusions are marked within the <properties> of the pom.xml 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>
    
Naman
  • 27,789
  • 26
  • 218
  • 353
  • Do you have an explanation of why this error occurs and why the exclusion is an acceptable solution? Indeed, I can solve the problem with an exclusion, but it's not really satisfactory to me. It's like having a compile error and "solving" it by commenting out the problematic line ;-) – dokaspar Oct 02 '17 at 07:06
  • @dokaspar Since the `sonar-maven-plugin` is in use the [documentation from the source as linked in answer](https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven#AnalyzingwithSonarQubeScannerforMaven-ProjectanalyzedwithMaven3) states configuring the sonar attributes into `properties` itself. – Naman Oct 02 '17 at 11:46