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

Add support for Java 11+ #736

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add support for Java 11+ #736

wants to merge 1 commit into from

Conversation

Col-E
Copy link

@Col-E Col-E commented Oct 6, 2022

NOTE: The work on this PR and a few others is mirrored on https://github.com/hazendaz/jmockit1/ since it seems like the maintainers of this project are MIA


Encountered some compatibility issues with a project due to outdated bytecode handling. This PR addresses the cases I've encountered personally but should also address the following issues:

Other changes under the hood:

  • Change bytecode handling to explicitly fail rather than assume a type in switch cases (Assisted in debugging, and failing makes the cause more clear than undefined behavior caused by ignoring the issue with fallback behavior)
  • Use full names instead of shorthand for constants (minor legibility improvement)
  • Use objenesis instead of direct sun reflection-factory for instance creation
  • Remove junit platform exclusion in pom.xml, resolving some failures with IntelliJ integration

Testing

You can test the validity of the changes within this project by forcing maven to execute the project in a Java 11+ context. I suggest the maven toolchain plugin for this:

Index: main/pom.xml
<+>UTF-8
===================================================================
diff --git a/main/pom.xml b/main/pom.xml
--- a/main/pom.xml	(revision 5c6a2dfc6042ebf8d99770a7e9167bf3c26149e8)
+++ b/main/pom.xml	(date 1665027301503)
@@ -66,10 +66,29 @@
       </resources>
       <plugins>
          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-toolchains-plugin</artifactId>
+            <version>3.1.0</version>
+            <configuration>
+               <toolchains>
+                  <jdk>
+                     <version>11</version>
+                  </jdk>
+               </toolchains>
+            </configuration>
+            <executions>
+               <execution>
+                  <goals>
+                     <goal>toolchain</goal>
+                  </goals>
+               </execution>
+            </executions>
+         </plugin>
+         <plugin>
             <artifactId>maven-compiler-plugin</artifactId><version>3.8.0</version>
             <configuration>
                <encoding>UTF-8</encoding>
-               <source>1.7</source><target>1.7</target>
+               <release>11</release>
                <compilerArgs><arg>-Xlint:none</arg></compilerArgs>
                <useIncrementalCompilation>false</useIncrementalCompilation>
             </configuration>

I tested up to Java 17 with all tests passing.

Change bytecode handling to explicitly fail rather than assume a type in switch cases
Use objenesis instead of direct sun reflection-factory for instance creation
Remove junit platform exclusion, resolving some failures with IntelliJ integration
@amosshi
Copy link

amosshi commented Oct 26, 2022

HI @rliesenfeld , @idstein , @gliptak

Need your help to review / merge this PR, thanks

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

Successfully merging this pull request may close these issues.

2 participants