Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
None
Description
The current implementation of CompilerConfiguration#setTargetBytecode(String) is to use the default version (currently "1.8") if the specified version is not supported. This can be a problem in joint compilation situations. If javac supports JDK19 or whatever comes along and groovyc only supports up to JDK17, then a target setting will be JDK19 for Java and JDK8 for Groovy.
In groovy-eclipse, I have been selecting the nearest version. So if the user asks for "19" and "17" is supported, they'll get that. And if the user asks for "1.3" (hypothetical) then they'll get "1.4". And if the user still uses "9.0" or "11.0" notation, they'll get what they expect.
public void setTargetBytecode(final String version) { setTargetBytecodeIfValid(version); } private void setTargetBytecodeIfValid(final String version) { /* GRECLIPSE edit if (JDK_TO_BYTECODE_VERSION_MAP.containsKey(version)) { this.targetBytecode = version; } */ int index; try { ALLOWED_JDKS[5] = "1.9"; // 9 is out of order for binary search index = Arrays.binarySearch(ALLOWED_JDKS, !version.startsWith("1") ? "1." + version : version); } finally { ALLOWED_JDKS[5] = "9"; } if (index >= 0) { targetBytecode = ALLOWED_JDKS[index]; } else { index = Math.abs(index) - 2; // closest version targetBytecode = ALLOWED_JDKS[Math.max(0, index)]; } // GRECLIPSE end }
Note: the current algorithm breaks down when "20" or greater is supplied.
Attachments
Issue Links
- relates to
-
GROOVY-10595 Compiler should fail for invalid targetBytecode values
- Closed
- links to