JavaSystem throws NumberFormatException each time it is loaded, as it tries to parse the Java version string (e.g. "21.0.6"), because this string is not an integer.
I don't claim that this is a bug, but it is an inconvenience for those of us who are developing systems that embed HSQLDB. For example, I am developing Morel. If I run Morel in a debugger and have a breakpoint set to trigger on IllegalArgumentException, this breakpoint fires every time I start the program. (NumberFormatException is a subclass of IllegalArgumentException, and therefore triggers the breakpoint.)
I would be grateful if you would apply the patch to trim the version string to an integer before parsing.
diff --git a/src/org/hsqldb/lib/java/JavaSystem.java b/src/org/hsqldb/lib/java/JavaSystem.java
index a27a8e11..c43a5985 100644
--- a/src/org/hsqldb/lib/java/JavaSystem.java
+++ b/src/org/hsqldb/lib/java/JavaSystem.java
@@ -60,10 +60,17 @@ public final class JavaSystem {
version = version.substring(2);
}
+ // If the version has one or more dots, we take the first part.
+ // For example, "11.0.2" becomes "11".
+ int dot = version.indexOf('.');
+ if (dot > 0) {
+ version = version.substring(0, dot);
+ }
+
javaVersion = Integer.parseInt(version);
} catch (Throwable t) {
- // unknow future version - default to last widely used
+ // unknown future version - default to last widely used
javaVersion = 11;
}
}
One caution. It is possible that all recent JDK versions have been throwing the exception, and therefore javaVersion has been set to 11. After this patch, javaVersion will be set correctly (e.g. to 21 for JDK 21.0.6). It's just possible that will break some things.
Ticket moved from /p/hsqldb/feature-requests/375/
Thanks. Will apply to the next release.
Fix committed to SVN.
Thank you, Fred! And thank you for all your work on HSQLDB. I have been a happy user for many years.