From eb2937f5f17a7fa0b2d86c5eca0571c2ef2b6b2b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 24 Mar 2026 05:25:15 +0000 Subject: [PATCH] Refactor Groovy version detection to use custom exception Replaced raw RuntimeException with GroovyVersionException in ClassWrangler. This improves maintainability and error handling by providing a more specific exception type and preserving the original cause. Key changes: - Created GroovyVersionException (unchecked) in util package. - Updated ClassWrangler.getGroovyVersion() to throw GroovyVersionException. - Updated ClassWrangler.getGroovyJar() to throw GroovyVersionException. - Included the original cause in the new exception for better debuggability. Co-authored-by: keeganwitt <64612+keeganwitt@users.noreply.github.com> --- .../gmavenplus/util/ClassWrangler.java | 4 +-- .../util/GroovyVersionException.java | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/codehaus/gmavenplus/util/GroovyVersionException.java diff --git a/src/main/java/org/codehaus/gmavenplus/util/ClassWrangler.java b/src/main/java/org/codehaus/gmavenplus/util/ClassWrangler.java index f503fecf..f841f14d 100644 --- a/src/main/java/org/codehaus/gmavenplus/util/ClassWrangler.java +++ b/src/main/java/org/codehaus/gmavenplus/util/ClassWrangler.java @@ -124,7 +124,7 @@ public Version getGroovyVersion() { try { return Version.parseFromString(getGroovyVersionString()); } catch (Exception e) { - throw new RuntimeException("Unable to determine Groovy version. Is Groovy declared as a dependency?"); + throw new GroovyVersionException("Unable to determine Groovy version. Is Groovy declared as a dependency?", e); } } @@ -259,7 +259,7 @@ protected String getGroovyJar() { return groovyJar; } catch (ClassNotFoundException e) { - throw new RuntimeException("Unable to determine Groovy version. Is Groovy declared as a dependency?"); + throw new GroovyVersionException("Unable to determine Groovy version. Is Groovy declared as a dependency?", e); } } diff --git a/src/main/java/org/codehaus/gmavenplus/util/GroovyVersionException.java b/src/main/java/org/codehaus/gmavenplus/util/GroovyVersionException.java new file mode 100644 index 00000000..104d9344 --- /dev/null +++ b/src/main/java/org/codehaus/gmavenplus/util/GroovyVersionException.java @@ -0,0 +1,30 @@ +package org.codehaus.gmavenplus.util; + +/** + * Exception thrown when Groovy version cannot be determined. + * + * @author Keegan Witt + * @since 4.3.2 + */ +public class GroovyVersionException extends RuntimeException { + + /** + * Constructs a new GroovyVersionException with the specified message. + * + * @param message the detail message + */ + public GroovyVersionException(final String message) { + super(message); + } + + /** + * Constructs a new GroovyVersionException with the specified message and cause. + * + * @param message the detail message + * @param cause the cause + */ + public GroovyVersionException(final String message, final Throwable cause) { + super(message, cause); + } + +}