Skip to content

Commit

Permalink
RecordElementsTests testPreviewFlagTrue fails since Java 20 is used
Browse files Browse the repository at this point in the history
- changed BaseProcessingEnvImpl to return minimal supported Java runtime
version as getSourceVersion() if the compiler version is higher as
current runtime version, not SourceVersion.RELEASE_6
- changed apt test to really expect latest supported SourceVersion, not
SourceVersion.RELEASE_6
- cleaned code a bit in BaseProcessingEnvImpl.getSourceVersion()
- regenerated apttestprocessors8.jar from apttestprocessors8.jardesc
- removed unneeded unsupported java profiles from test pom files
- the code should be able to run without changes also on Java 21+

Fixes #994
  • Loading branch information
iloveeclipse committed May 8, 2023
1 parent 6fec0f8 commit 4bbbe1f
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 431 deletions.
32 changes: 16 additions & 16 deletions org.eclipse.jdt.compiler.apt.tests/apttestprocessors8.jardesc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jardesc>
<jar path="org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/org.eclipse.jdt.compiler.apt.tests/apttestprocessors8.jardesc" exportErrors="false" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
Expand All @@ -11,20 +11,20 @@
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="true" exportOutputFolder="false">
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.filer"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors8"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.annotations"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.elementutils"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.visitors"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.elements"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.messager"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.checkargs"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.genclass"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.negative"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.typeutils"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.typemirror"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.base"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.generics"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors&lt;org.eclipse.jdt.compiler.apt.tests.processors.inherited"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.visitors"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.elementutils"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.filer"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.elements"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors8=/test=/true=/"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.typemirror"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.generics"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.checkargs"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.negative"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.genclass"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.typeutils"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.messager"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.base"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.processors.inherited"/>
<javaElement handleIdentifier="=org.eclipse.jdt.compiler.apt.tests/processors=/test=/true=/&lt;org.eclipse.jdt.compiler.apt.tests.annotations"/>
</selectedElements>
</jardesc>
Binary file modified org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public void testPreviewFlagTrue() throws IOException {
assertTrue("Preview flag not seen as enabled", preview);
}
SourceVersion sourceVersion = this.processingEnv.getSourceVersion();
assertEquals("Should support the latest compliance", sourceVersion, SourceVersion.RELEASE_6);
SourceVersion expected = SourceVersion.valueOf("RELEASE_" + Runtime.version().feature());
assertEquals("Should support the latest compliance", expected, sourceVersion);
}
/*
* Basic test for record element and kind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.jdt.internal.compiler.apt.model.TypesImpl;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
Expand All @@ -42,6 +43,12 @@
*/
public abstract class BaseProcessingEnvImpl implements ProcessingEnvironment {

/**
* The minimal required Java runtime version (we need to run compiler on)
*/
public static final SourceVersion MINIMAL_REQUIRED_RUNTIME_VERSION = SourceVersion.RELEASE_17;
private static final long VERSION_FOR_MINIMAL_RUNTIME = ClassFileConstants.JDK17;

// Initialized in subclasses:
protected Filer _filer;
protected Messager _messager;
Expand Down Expand Up @@ -123,61 +130,49 @@ public LookupEnvironment getLookupEnvironment() {

@Override
public SourceVersion getSourceVersion() {
if (this._compiler.options.sourceLevel <= ClassFileConstants.JDK1_5) {
final long sourceLevel = this._compiler.options.sourceLevel;
if (sourceLevel <= ClassFileConstants.JDK1_5) {
return SourceVersion.RELEASE_5;
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK1_6) {
if (sourceLevel == ClassFileConstants.JDK1_6) {
return SourceVersion.RELEASE_6;
} else if (sourceLevel == ClassFileConstants.JDK1_7) {
return SourceVersion.RELEASE_7;
} else if (sourceLevel == ClassFileConstants.JDK1_8) {
return SourceVersion.RELEASE_8;
} else if (sourceLevel == ClassFileConstants.JDK9) {
return SourceVersion.RELEASE_9;
} else if (sourceLevel == ClassFileConstants.JDK10) {
return SourceVersion.RELEASE_10;
} else if (sourceLevel == ClassFileConstants.JDK11) {
return SourceVersion.RELEASE_11;
} else if (sourceLevel == ClassFileConstants.JDK12) {
return SourceVersion.RELEASE_12;
} else if (sourceLevel == ClassFileConstants.JDK13) {
return SourceVersion.RELEASE_13;
} else if (sourceLevel == ClassFileConstants.JDK14) {
return SourceVersion.RELEASE_14;
} else if (sourceLevel == ClassFileConstants.JDK15) {
return SourceVersion.RELEASE_15;
} else if (sourceLevel == ClassFileConstants.JDK16) {
return SourceVersion.RELEASE_16;
} else if (sourceLevel == ClassFileConstants.JDK17) {
return SourceVersion.RELEASE_17;
}
try {
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK1_7) {
return SourceVersion.valueOf("RELEASE_7"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK1_8) {
return SourceVersion.valueOf("RELEASE_8"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK9) {
return SourceVersion.valueOf("RELEASE_9"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK10) {
return SourceVersion.valueOf("RELEASE_10"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK11) {
return SourceVersion.valueOf("RELEASE_11"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK12) {
return SourceVersion.valueOf("RELEASE_12"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK13) {
return SourceVersion.valueOf("RELEASE_13"); //$NON-NLS-1$
// From here on we can't use constants that may not be yet defined in
// minimal required runtime Java version we have to avoid
// errors like java.lang.NoSuchFieldError: RELEASE_20
if (sourceLevel > VERSION_FOR_MINIMAL_RUNTIME) {
try {
return SourceVersion.valueOf("RELEASE_" + CompilerOptions.versionFromJdkLevel(sourceLevel)); //$NON-NLS-1$
} catch (IllegalArgumentException e) {
// handle call on a minimal release we can run on
return MINIMAL_REQUIRED_RUNTIME_VERSION;
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK14) {
return SourceVersion.valueOf("RELEASE_14"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK15) {
return SourceVersion.valueOf("RELEASE_15"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK16) {
return SourceVersion.valueOf("RELEASE_16"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK17) {
return SourceVersion.valueOf("RELEASE_17"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK18) {
return SourceVersion.valueOf("RELEASE_18"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK19) {
return SourceVersion.valueOf("RELEASE_19"); //$NON-NLS-1$
}
if (this._compiler.options.sourceLevel == ClassFileConstants.JDK20) {
return SourceVersion.valueOf("RELEASE_20"); //$NON-NLS-1$
}
} catch(IllegalArgumentException e) {
// handle call on a JDK 6
return SourceVersion.RELEASE_6;
} else {
// to make compiler happy, should never happen
throw new IllegalStateException("Invalid JDK source level: " + sourceLevel); //$NON-NLS-1$
}
// handle call on a JDK 6 by default
return SourceVersion.RELEASE_6;
}

/**
Expand Down
35 changes: 6 additions & 29 deletions org.eclipse.jdt.core.tests.builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<profiles>
<profile>
<id>test-on-javase-9</id>
<id>test-on-javase-17</id>
<build>
<plugins>
<plugin>
Expand All @@ -53,19 +53,19 @@
<configuration>
<toolchains>
<jdk>
<id>JavaSE-9</id>
<id>JavaSE-17</id>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM</tycho.surefire.argLine>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,17</tycho.surefire.argLine>
</properties>
</profile>
<profile>
<id>test-on-javase-10</id>
<id>test-on-javase-20</id>
<build>
<plugins>
<plugin>
Expand All @@ -74,38 +74,15 @@
<configuration>
<toolchains>
<jdk>
<id>JavaSE-10</id>
<id>JavaSE-20</id>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- Overridden in https://ci.eclipse.org/jdt/job/eclipse.jdt.core-run.javac-10/configure -->
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,10</tycho.surefire.argLine>
</properties>
</profile>
<profile>
<id>test-on-javase-11</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<configuration>
<toolchains>
<jdk>
<id>JavaSE-11</id>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- Overridden in https://ci.eclipse.org/jdt/job/eclipse.jdt.core-run.javac-11/configure -->
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,11</tycho.surefire.argLine>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=1.4,1.7,1.8,20</tycho.surefire.argLine>
</properties>
</profile>
</profiles>
Expand Down
Loading

0 comments on commit 4bbbe1f

Please sign in to comment.