jamesfredley commented on code in PR #15598:
URL: https://github.com/apache/grails-core/pull/15598#discussion_r3139872086
##########
grails-wrapper/src/main/java/grails/init/GrailsVersion.java:
##########
@@ -138,29 +193,18 @@ public static GrailsVersion getPreferredGrailsVersion() {
System.exit(1);
}
- if (!properties.containsKey("grailsVersion")) {
+ if (!properties.containsKey(GRAILS_VERSION_PROPERTY)) {
return null;
}
- String grailsVersion = properties.getProperty("grailsVersion");
- if (grailsVersion == null) {
- String overrideGrailsVersion =
System.getenv("PREFERRED_GRAILS_VERSION");
- if (overrideGrailsVersion != null) {
- try {
- return new GrailsVersion(overrideGrailsVersion);
- } catch (Exception e) {
- System.out.println("An invalid Grails Version [" +
overrideGrailsVersion + "] was specified in PREFERRED_GRAILS_VERSION");
- e.printStackTrace();
- System.exit(1);
- }
- }
-
- System.out.println("gradle.properties does not contain
grailsVersion; assuming latest Grails Version");
- return null;
+ String grailsVersion = properties.getProperty(GRAILS_VERSION_PROPERTY);
+ if (grailsVersion == null || grailsVersion.trim().isEmpty()) {
+ System.out.println("A blank Grails Version was specified in
gradle.properties for key [" + GRAILS_VERSION_PROPERTY + "]");
+ System.exit(1);
}
try {
- return new GrailsVersion(grailsVersion);
+ return new GrailsVersion(grailsVersion.trim());
Review Comment:
Addressed in fd73cf35f2f8b7cd47a4ed5a3c867b1b18eb0442. Moved `.trim()` up to
the variable definition for `grailsVersion` (and symmetrically for the
`PREFERRED_GRAILS_VERSION` env var path) so each method uses the trimmed form
consistently and the raw form is only retained to surface the original user
input in the error message.
While I was there I also fixed the `grails-wrapper:test` failure on every
JDK 21+ matrix cell (ubuntu-21/25, macos-21, windows-25). Root cause was
`SystemStubs.catchSystemExit` relying on `System.setSecurityManager`, which
throws `UnsupportedOperationException` on JDK 21 without
`-Djava.security.manager=allow` and will be removed permanently in JDK 24+ (JEP
486) - no flag keeps that API working across our matrix. Refactored
`getPreferredGrailsVersion(File)` and `readVersionFromProperties` to throw
`IllegalStateException` on misconfiguration, with the no-arg public
`getPreferredGrailsVersion()` being the single call site that translates to
`System.exit(1)` for CLI behaviour preservation. The spec now asserts
`thrown(IllegalStateException)` directly and pins the message, no JVM-level
interception needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]