Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-67960] Work around MCOMPILER-346 #235

Merged
merged 1 commit into from Mar 5, 2022

Conversation

basil
Copy link
Member

@basil basil commented Mar 5, 2022

Background

See JENKINS-67960 and MCOMPILER-346. I have run into this bug repeatedly while working on Jenkins, most recently in jenkinsci/acceptance-test-harness#733.

Problem

When compiling Jenkins code with compilation errors with Java 11, MCOMPILER-346 is frequently encountered. If you encounter it with -source 8, you get a NullPointerException. If you encounter it with -source 11, you get an AssertionError. Either way, you do not get a readable message with the compilation error. Therefore, you have no idea what you need to fix in order to get the code to compile.

Solution

TBD. MCOMPILER-346 has remained open since June 28, 2018. I submitted a Minimal Reproducible Example (MRE) hoping that this will help the Maven developers resolve the issue.

Workaround

In the past, I have worked around this issue by switching back to Java 8. This works with -source 8, but it does not work with -source 11 for obvious reasons. Therefore, a new workaround is needed. I have just discovered a new workaround: running Maven with -Dmaven.compiler.forceJavacCompilerUse=true. Until MCOMPILER-346 is fixed, we should enable this workaround by default for all Jenkins builds. Otherwise, people compiling with Java 11 will get strange NullPointerExceptions or AssertionErrors when their code does not compile rather than a comprehensible error message explaining the source of the compilation error.

Testing done

Reproduced the failure from jenkinsci/acceptance-test-harness#733 locally. Then upgraded the POM to the one from this PR and could no longer reproduce the issue. Instead, I got a comprehensible error message.

@basil basil merged commit 05876b4 into jenkinsci:master Mar 5, 2022
@basil basil deleted the JENKINS-67960 branch March 5, 2022 15:32
@olamy
Copy link
Member

olamy commented Mar 6, 2022

for reference the root cause is a jdk bug https://bugs.openjdk.java.net/browse/JDK-8210649
the best workaround is to have project compiling correctly 😜😂
but yeah the m-compiler-p should have a workaround for this...

@olamy
Copy link
Member

olamy commented Mar 6, 2022

few other workaround until next m-compiler-p release.

  • override plexus-compiler dependency
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.10.0</version>
        <configuration>
          <release>11</release>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-compiler-api</artifactId>
            <version>2.11.0</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-compiler-javac</artifactId>
            <version>2.11.0</version>
          </dependency>
        </dependencies>
      </plugin>
  • make a JEP to upgrade to jdk 17 as the bug does not exist anymore
  • make sure code compile

I will try to release m-compiler-p really soon.
using forceJavacCompilerUse might slow down just a bit build but it's probably not human noticeable on small build such Jenkins builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants