Skip to content

Commit eb56b6e

Browse files
committed
Add Java23 support
The huge change with adopting Java23 is that 1.1 > 1.7 Java are now considered unsupported by Eclipse JDT, so the many thousands of tests we have that were specifying java versions lower than 1.8 were all failing with an unsupported version error. All those tests have had their versions bumped to 1.8.

That is why this commit includes so many changes. For example where we were specifying 1.5 - which was the case for many many generics/annotations tests, that is now 1.8. Also, some tests have been deleted because they make no sense now (verifying expected errors on Java 1.4 for example, errors that just can’t happen with minimum Java level 1.8). The biggest impact to tests was when bumping above 1.4 compliance suddenly there were 100s of adviceDidNotMatch messages. Some of these messages were actual indications of bad expectations in the test but many of them were just to-be-expected and were fixed either via an -Xlint:ignore option in the test spec or a SuppressAjWarnings in the test source.

One or two tests actually revealed real bugs that just didn’t surface with lower level java versions specified. A bare minimum of real Java 23 tests have been added just to get this sanity tested and committed. More would ideally be added. Other notable changes due to Eclipse JDT changes: org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/*.java Changes in here because there are now more validations on the code generator methods we were calling. Now you can’t start manipulating variables without having declared them as proper local variables, so those extra calls to define them have been added.
 org.aspectj.ajdt.core/src/org/aspectj/org/eclipse/jdt/core/dom With needing to bump up the java versions, these classes had to be brought up to date with AST.JLS20 rather than only supporting versions 2/3. This was mostly copying patterns for the Eclipse classes.


1 parent 8044fa1 commit eb56b6e

File tree

224 files changed

+3857
-3228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+3857
-3228
lines changed

ajde.core/src/main/java/org/aspectj/ajde/core/JavaOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public final class JavaOptions {
2828
public static final String VERSION_14 = CompilerOptions.VERSION_1_4;
2929
public static final String VERSION_15 = CompilerOptions.VERSION_1_5;
3030
public static final String VERSION_16 = CompilerOptions.VERSION_1_6;
31+
public static final String VERSION_17 = CompilerOptions.VERSION_1_7;
32+
public static final String VERSION_18 = CompilerOptions.VERSION_1_8;
3133

3234
// by default will use the platform default encoding
3335
public static final String CHARACTER_ENCODING = CompilerOptions.OPTION_Encoding;

ajde.core/src/test/java/org/aspectj/ajde/core/TestCompilerConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public Set<File> getInpath() {
7777
public Map<String, String> getJavaOptionsMap() {
7878
if (javaOptions == null) {
7979
javaOptions = new Hashtable<>();
80-
javaOptions.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_13);
81-
javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_13);
80+
javaOptions.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_18);
81+
javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_18);
8282
}
8383
return javaOptions;
8484
}

ajde.core/src/test/java/org/aspectj/ajde/core/tests/ShowWeaveMessagesTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ public void testWeaveMessagesDeclareAnnotation() {
166166
if (debugTests)
167167
System.out.println("\ntestWeaveMessagesDeclareAnnotation: Building with Six.lst");
168168
compilerConfig.setProjectSourceFiles(getSourceFileList(six));
169-
setRunIn15Mode();
170-
compilerConfig.setNonStandardOptions("-showWeaveInfo -1.5");
169+
setRunIn18Mode();
170+
compilerConfig.setNonStandardOptions("-showWeaveInfo -1.8");
171171
doBuild();
172172
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());
173173
verifyWeavingMessages("declare.annotation", true);
@@ -182,7 +182,7 @@ public void testWeaveMessagesDeclareAnnotationWeaveInfoOff() {
182182
System.out.println("\ntestWeaveMessagesDeclareAnnotation: Building with Seven.lst");
183183
compilerConfig.setProjectSourceFiles(getSourceFileList(seven));
184184
compilerConfig.setNonStandardOptions("");
185-
setRunIn15Mode();
185+
setRunIn18Mode();
186186
doBuild();
187187
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());
188188
verifyWeavingMessages("declare.annotationNoWeaveInfo", true);
@@ -423,11 +423,11 @@ private void saveWeaveMessages(File f) {
423423
}
424424
}
425425

426-
private void setRunIn15Mode() {
426+
private void setRunIn18Mode() {
427427
Map<String, String> m = new Hashtable<>();
428-
m.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_15);
429-
m.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_15);
430-
m.put(JavaOptions.TARGET_COMPATIBILITY_LEVEL, JavaOptions.VERSION_15);
428+
m.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_18);
429+
m.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_18);
430+
m.put(JavaOptions.TARGET_COMPATIBILITY_LEVEL, JavaOptions.VERSION_18);
431431
compilerConfig.setJavaOptions(m);
432432
}
433433

ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserViewManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class BrowserViewManager {
4848
private final GlobalViewProperties INHERITANCE_VIEW_PROPERTIES;
4949

5050
public BrowserViewManager() {
51-
java.util.List views = new ArrayList();
51+
java.util.List<GlobalStructureView> views = new ArrayList<>();
5252
views.add(DECLARATION_VIEW);
5353
views.add(CROSSCUTTING_VIEW);
5454
views.add(INHERITANCE_VIEW);

ajde/src/test/java/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public class TestCompilerConfiguration implements ICompilerConfiguration {
3737

3838
private String projectPath;
3939

40-
private Set aspectpath;
41-
private Set inpath;
40+
private Set<File> aspectpath;
41+
private Set<File> inpath;
4242
private String outjar;
4343
private Map<String,String> javaOptions;
4444
private String nonStandardOptions;
45-
private List projectSourceFiles = new ArrayList();
46-
private Map sourcePathResources;
45+
private List<String> projectSourceFiles = new ArrayList<>();
46+
private Map<String,File> sourcePathResources;
4747

4848
private String srcDirName = "src";
4949

@@ -56,11 +56,11 @@ public TestCompilerConfiguration(String projectPath) {
5656
public void configurationRead() {
5757
}
5858

59-
public List getProjectXmlConfigFiles() {
60-
return Collections.EMPTY_LIST;
59+
public List<String> getProjectXmlConfigFiles() {
60+
return Collections.emptyList();
6161
}
6262

63-
public Set getAspectPath() {
63+
public Set<File> getAspectPath() {
6464
return aspectpath;
6565
}
6666

@@ -73,15 +73,15 @@ public String getClasspath() {
7373
return cp;
7474
}
7575

76-
public Set getInpath() {
76+
public Set<File> getInpath() {
7777
return inpath;
7878
}
7979

8080
public Map<String,String> getJavaOptionsMap() {
8181
if (javaOptions == null) {
8282
javaOptions = new Hashtable<>();
83-
javaOptions.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_13);
84-
javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_13);
83+
javaOptions.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_18);
84+
javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_18);
8585
}
8686
return javaOptions;
8787
}
@@ -101,17 +101,17 @@ public IOutputLocationManager getOutputLocationManager() {
101101
return outputLoc;
102102
}
103103

104-
public List getProjectSourceFiles() {
104+
public List<String> getProjectSourceFiles() {
105105
return projectSourceFiles;
106106
}
107107

108-
public List getProjectSourceFilesChanged() {
108+
public List<File> getProjectSourceFilesChanged() {
109109
return null;
110110
}
111111

112-
public Map getSourcePathResources() {
112+
public Map<String,File> getSourcePathResources() {
113113
if (sourcePathResources == null) {
114-
sourcePathResources = new HashMap();
114+
sourcePathResources = new HashMap<>();
115115

116116
/* Allow the user to override the testProjectPath by using sourceRoots */
117117
File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) };
@@ -127,39 +127,38 @@ public boolean accept(File pathname) {
127127
for (File fromResource : fromResources) {
128128
String normPath = FileUtil.normalizedPath(fromResource, file);
129129
sourcePathResources.put(normPath, fromResource);
130-
131130
}
132131
}
133132
}
134133
return sourcePathResources;
135134
}
136135

137136
// -------------------- setter methods useful for testing ---------------
138-
public void setAspectPath(Set aspectPath) {
137+
public void setAspectPath(Set<File> aspectPath) {
139138
this.aspectpath = aspectPath;
140139
}
141140

142-
public void setInpath(Set inpath) {
141+
public void setInpath(Set<File> inpath) {
143142
this.inpath = inpath;
144143
}
145144

146145
public void setOutjar(String outjar) {
147146
this.outjar = outjar;
148147
}
149148

150-
public void setJavaOptions(Map javaOptions) {
149+
public void setJavaOptions(Map<String,String> javaOptions) {
151150
this.javaOptions = javaOptions;
152151
}
153152

154153
public void setNonStandardOptions(String options) {
155154
this.nonStandardOptions = options;
156155
}
157156

158-
public void setProjectSourceFiles(List projectSourceFiles) {
157+
public void setProjectSourceFiles(List<String> projectSourceFiles) {
159158
this.projectSourceFiles = projectSourceFiles;
160159
}
161160

162-
public void setSourcePathResources(Map sourcePathResources) {
161+
public void setSourcePathResources(Map<String,File> sourcePathResources) {
163162
this.sourcePathResources = sourcePathResources;
164163
}
165164

@@ -171,7 +170,7 @@ public int getConfigurationChanges() {
171170
return ICompilerConfiguration.EVERYTHING;
172171
}
173172

174-
public List getClasspathElementsWithModifiedContents() {
173+
public List<String> getClasspathElementsWithModifiedContents() {
175174
return null;
176175
}
177176

ajdoc/src/test/java/org/aspectj/tools/ajdoc/BugTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void testPr148906_1() {
3737
initialiseProject("pr148906");
3838
File[] files = {new File(getAbsoluteProjectDir() + "/AdviceDidNotMatch.aj")};
3939
String[] ajOptions = {new String("-Xlint:error")};
40-
runAjdoc(files,"1.5",ajOptions);
40+
runAjdoc(files,"1.8",ajOptions);
4141
assertTrue("expected ajc to fail but it did not", Main.hasAborted());
4242
assertEquals("expected ajc to fail with an adviceDidNotMatch error but it" +
4343
" failed instead with " + Main.getErrors()[0].getMessage(),
@@ -53,7 +53,7 @@ public void testPr148906_2() {
5353
initialiseProject("pr148906");
5454
File[] files = {new File(getAbsoluteProjectDir() + "/AdviceDidNotMatch.aj")};
5555
String[] ajOptions = {new String("-Xlintfile"), new String(getAbsoluteProjectDir() + File.separator + "Xlint.properties")};
56-
runAjdoc(files,"1.5",ajOptions);
56+
runAjdoc(files,"1.8",ajOptions);
5757
assertTrue("expected ajc to fail but it did not", Main.hasAborted());
5858
assertEquals("expected ajc to fail with an adviceDidNotMatch error but it" +
5959
" failed instead with " + Main.getErrors()[0].getMessage(),

lib/aspectj/lib/aspectjrt.jar

7 Bytes
Binary file not shown.

lib/aspectj/lib/aspectjtools.jar

146 KB
Binary file not shown.

lib/aspectj/lib/aspectjweaver.jar

4.01 KB
Binary file not shown.

org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/BuildArgParser.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.aspectj.bridge.Version;
3636
import org.aspectj.org.eclipse.jdt.core.compiler.CategorizedProblem;
3737
import org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.AptProblem;
38+
import org.aspectj.org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
3839
import org.aspectj.org.eclipse.jdt.internal.compiler.batch.FileSystem;
3940
import org.aspectj.org.eclipse.jdt.internal.compiler.batch.Main;
4041
import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
@@ -166,7 +167,8 @@ public AjBuildConfig populateBuildConfig(AjBuildConfig buildConfig, String[] arg
166167
super.configure(javaArgList.toArray(new String[0]));
167168

168169
if (parser.getModuleInfoArgument() != null) {
169-
IModule moduleDesc = super.getModuleDesc(parser.getModuleInfoArgument());
170+
IModule moduleDesc = super.getModuleDesc(parser.getModuleInfoArgument(),
171+
() -> new CompilationUnit(null, parser.getModuleInfoArgument(), null));
170172
buildConfig.setModuleDesc(moduleDesc);
171173
}
172174

@@ -382,7 +384,7 @@ public ArrayList<FileSystem.Classpath> handleClasspath(ArrayList<String> classpa
382384
* If the classpath is not set, we use the environment's java.class.path, but remove the aspectjtools.jar entry from that list
383385
* in order to prevent wierd bootstrap issues (refer to bug#39959).
384386
*/
385-
public List getClasspath(AjcConfigParser parser) {
387+
public List<String> getClasspath(AjcConfigParser parser) {
386388
List<String> ret = new ArrayList<>();
387389

388390
// if (parser.bootclasspath == null) {
@@ -904,14 +906,38 @@ private int indexOf(Iterable<Arg> args, String arg) {
904906

905907
}
906908

907-
@Override
908-
public boolean checkVMVersion(long minimalSupportedVersion) {
909-
return super.checkVMVersion(minimalSupportedVersion);
910-
}
909+
// @Override
910+
// public boolean checkVMVersion(long minimalSupportedVersion) {
911+
// return super.checkVMVersion(minimalSupportedVersion);
912+
// }
911913

912914
@Override
913915
public void initRootModules(LookupEnvironment environment, FileSystem fileSystem) {
914916
super.initRootModules(environment, fileSystem);
915917
}
918+
919+
// Around Java23, looks like JDT has removed this and is just assuming 'modern' Java.
920+
// This is what they had in org.eclipse.jdt.internal.compiler.batch.Main.checkVMVersion()
921+
public boolean checkVMVersion(long minimalSupportedVersion) {
922+
// the format of this property is supposed to be xx.x where x are digits.
923+
String classFileVersion = System.getProperty("java.class.version"); //$NON-NLS-1$
924+
if (classFileVersion == null) {
925+
// by default we don't support a class file version we cannot recognize
926+
return false;
927+
}
928+
int index = classFileVersion.indexOf('.');
929+
if (index == -1) {
930+
// by default we don't support a class file version we cannot recognize
931+
return false;
932+
}
933+
int majorVersion;
934+
try {
935+
majorVersion = Integer.parseInt(classFileVersion.substring(0, index));
936+
} catch (NumberFormatException e) {
937+
// by default we don't support a class file version we cannot recognize
938+
return false;
939+
}
940+
return ClassFileConstants.getComplianceLevelForJavaVersion(majorVersion) >=minimalSupportedVersion;
941+
}
916942

917943
}

0 commit comments

Comments
 (0)