From 7a798287a1948c2b57c672d100e3db6b009ade9b Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Tue, 23 Jan 2024 08:47:39 -0600 Subject: [PATCH] Change the return type of certain `Assert` methods. This is a backwards-compatible change using the `bridger` tool. See https://www.morling.dev/blog/refining-return-type-java-methods-without-breaking-backwards-compatibility/ for more information about retaining binary compatibility using bridge methods. --- constraint/pom.xml | 4 + .../io/smallrye/common/constraint/Assert.java | 180 ++++++++++++++++-- pom.xml | 15 ++ 3 files changed, 183 insertions(+), 16 deletions(-) diff --git a/constraint/pom.xml b/constraint/pom.xml index 589e019e..d3166e65 100644 --- a/constraint/pom.xml +++ b/constraint/pom.xml @@ -33,6 +33,10 @@ io.github.dmlloyd.module-info module-info + + org.jboss.bridger + bridger + diff --git a/constraint/src/main/java/io/smallrye/common/constraint/Assert.java b/constraint/src/main/java/io/smallrye/common/constraint/Assert.java index f52136c6..da917524 100644 --- a/constraint/src/main/java/io/smallrye/common/constraint/Assert.java +++ b/constraint/src/main/java/io/smallrye/common/constraint/Assert.java @@ -262,13 +262,23 @@ public static double[] checkNotEmptyParam(String name, double[] value) { * @param min the minimum value * @param actual the actual parameter value * @param the parameter type + * @return the given actual value * @throws IllegalArgumentException if the actual value is less than the minimum value */ - public static > void checkMinimumParameter(String name, T min, T actual) + public static > T checkMinimumParameter(String name, T min, T actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual.compareTo(min) < 0) throw Messages.log.paramLessThan(name, min); + return actual; + } + + /** + * @hidden + */ + public static > void checkMinimumParameter$$bridge(String name, T min, T actual) + throws IllegalArgumentException { + checkMinimumParameter(name, min, actual); } /** @@ -277,12 +287,21 @@ public static > void checkMinimumParameter(String name, * @param name the parameter name * @param min the minimum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is less than the minimum value */ - public static void checkMinimumParameter(String name, int min, int actual) throws IllegalArgumentException { + public static int checkMinimumParameter(String name, int min, int actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual < min) throw Messages.log.paramLessThan(name, min); + return actual; + } + + /** + * @hidden + */ + public static void checkMinimumParameter$$bridge(String name, int min, int actual) throws IllegalArgumentException { + checkMinimumParameter(name, min, actual); } /** @@ -291,12 +310,21 @@ public static void checkMinimumParameter(String name, int min, int actual) throw * @param name the parameter name * @param min the minimum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is less than the minimum value */ - public static void checkMinimumParameterUnsigned(String name, int min, int actual) throws IllegalArgumentException { + public static int checkMinimumParameterUnsigned(String name, int min, int actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (Integer.compareUnsigned(actual, min) < 0) throw Messages.log.paramLessThan(name, Integer.toUnsignedLong(min)); + return actual; + } + + /** + * @hidden + */ + public static void checkMinimumParameterUnsigned$$bridge(String name, int min, int actual) throws IllegalArgumentException { + checkMinimumParameterUnsigned(name, min, actual); } /** @@ -305,12 +333,21 @@ public static void checkMinimumParameterUnsigned(String name, int min, int actua * @param name the parameter name * @param min the minimum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is less than the minimum value */ - public static void checkMinimumParameter(String name, long min, long actual) throws IllegalArgumentException { + public static long checkMinimumParameter(String name, long min, long actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual < min) throw Messages.log.paramLessThan(name, min); + return actual; + } + + /** + * @hidden + */ + public static void checkMinimumParameter$$bridge(String name, long min, long actual) throws IllegalArgumentException { + checkMinimumParameter(name, min, actual); } /** @@ -319,12 +356,22 @@ public static void checkMinimumParameter(String name, long min, long actual) thr * @param name the parameter name * @param min the minimum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is less than the minimum value */ - public static void checkMinimumParameterUnsigned(String name, long min, long actual) throws IllegalArgumentException { + public static long checkMinimumParameterUnsigned(String name, long min, long actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (Long.compareUnsigned(actual, min) < 0) throw Messages.log.paramLessThan(name, Long.toUnsignedString(min)); + return actual; + } + + /** + * @hidden + */ + public static void checkMinimumParameterUnsigned$$bridge(String name, long min, long actual) + throws IllegalArgumentException { + checkMinimumParameterUnsigned(name, min, actual); } /** @@ -333,12 +380,21 @@ public static void checkMinimumParameterUnsigned(String name, long min, long act * @param name the parameter name * @param min the minimum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is less than the minimum value */ - public static void checkMinimumParameter(String name, float min, float actual) throws IllegalArgumentException { + public static float checkMinimumParameter(String name, float min, float actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual < min) throw Messages.log.paramLessThan(name, min); + return actual; + } + + /** + * @hidden + */ + public static void checkMinimumParameter$$bridge(String name, float min, float actual) throws IllegalArgumentException { + checkMinimumParameter(name, min, actual); } /** @@ -347,12 +403,21 @@ public static void checkMinimumParameter(String name, float min, float actual) t * @param name the parameter name * @param min the minimum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is less than the minimum value */ - public static void checkMinimumParameter(String name, double min, double actual) throws IllegalArgumentException { + public static double checkMinimumParameter(String name, double min, double actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual < min) throw Messages.log.paramLessThan(name, min); + return actual; + } + + /** + * @hidden + */ + public static void checkMinimumParameter$$bridge(String name, double min, double actual) throws IllegalArgumentException { + checkMinimumParameter(name, min, actual); } /** @@ -362,13 +427,23 @@ public static void checkMinimumParameter(String name, double min, double actual) * @param max the maximum value * @param actual the actual parameter value * @param the parameter type + * @return the given actual value * @throws IllegalArgumentException if the actual value is greater than the maximum value */ - public static > void checkMaximumParameter(String name, T max, T actual) + public static > T checkMaximumParameter(String name, T max, T actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual.compareTo(max) > 0) throw Messages.log.paramGreaterThan(name, max); + return actual; + } + + /** + * @hidden + */ + public static > void checkMaximumParameter$$bridge(String name, T max, T actual) + throws IllegalArgumentException { + checkMaximumParameter(name, max, actual); } /** @@ -377,12 +452,21 @@ public static > void checkMaximumParameter(String name, * @param name the parameter name * @param max the maximum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is greater than the maximum value */ - public static void checkMaximumParameter(String name, int max, int actual) throws IllegalArgumentException { + public static int checkMaximumParameter(String name, int max, int actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual > max) throw Messages.log.paramGreaterThan(name, max); + return actual; + } + + /** + * @hidden + */ + public static void checkMaximumParameter$$bridge(String name, int max, int actual) throws IllegalArgumentException { + checkMaximumParameter(name, max, actual); } /** @@ -391,12 +475,21 @@ public static void checkMaximumParameter(String name, int max, int actual) throw * @param name the parameter name * @param max the maximum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is greater than the maximum value */ - public static void checkMaximumParameterUnsigned(String name, int max, int actual) throws IllegalArgumentException { + public static int checkMaximumParameterUnsigned(String name, int max, int actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (Integer.compareUnsigned(actual, max) > 0) throw Messages.log.paramGreaterThan(name, Integer.toUnsignedLong(max)); + return actual; + } + + /** + * @hidden + */ + public static void checkMaximumParameterUnsigned$$bridge(String name, int max, int actual) throws IllegalArgumentException { + checkMaximumParameterUnsigned(name, max, actual); } /** @@ -405,12 +498,21 @@ public static void checkMaximumParameterUnsigned(String name, int max, int actua * @param name the parameter name * @param max the maximum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is greater than the maximum value */ - public static void checkMaximumParameter(String name, long max, long actual) throws IllegalArgumentException { + public static long checkMaximumParameter(String name, long max, long actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual > max) throw Messages.log.paramGreaterThan(name, max); + return actual; + } + + /** + * @hidden + */ + public static void checkMaximumParameter$$bridge(String name, long max, long actual) throws IllegalArgumentException { + checkMaximumParameter(name, max, actual); } /** @@ -419,12 +521,22 @@ public static void checkMaximumParameter(String name, long max, long actual) thr * @param name the parameter name * @param max the maximum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is greater than the maximum value */ - public static void checkMaximumParameterUnsigned(String name, long max, long actual) throws IllegalArgumentException { + public static long checkMaximumParameterUnsigned(String name, long max, long actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (Long.compareUnsigned(actual, max) > 0) throw Messages.log.paramGreaterThan(name, Long.toUnsignedString(max)); + return actual; + } + + /** + * @hidden + */ + public static void checkMaximumParameterUnsigned$$bridge(String name, long max, long actual) + throws IllegalArgumentException { + checkMaximumParameterUnsigned(name, max, actual); } /** @@ -433,12 +545,21 @@ public static void checkMaximumParameterUnsigned(String name, long max, long act * @param name the parameter name * @param max the maximum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is greater than the maximum value */ - public static void checkMaximumParameter(String name, float max, float actual) throws IllegalArgumentException { + public static float checkMaximumParameter(String name, float max, float actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual > max) throw Messages.log.paramGreaterThan(name, max); + return actual; + } + + /** + * @hidden + */ + public static void checkMaximumParameter$$bridge(String name, float max, float actual) throws IllegalArgumentException { + checkMaximumParameter(name, max, actual); } /** @@ -447,12 +568,21 @@ public static void checkMaximumParameter(String name, float max, float actual) t * @param name the parameter name * @param max the maximum value * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is greater than the maximum value */ - public static void checkMaximumParameter(String name, double max, double actual) throws IllegalArgumentException { + public static double checkMaximumParameter(String name, double max, double actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual > max) throw Messages.log.paramGreaterThan(name, max); + return actual; + } + + /** + * @hidden + */ + public static void checkMaximumParameter$$bridge(String name, double max, double actual) throws IllegalArgumentException { + checkMaximumParameter(name, max, actual); } /** @@ -461,12 +591,21 @@ public static void checkMaximumParameter(String name, double max, double actual) * * @param name the parameter name * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is not zero or a power of two */ - public static void checkPow2Parameter(String name, int actual) throws IllegalArgumentException { + public static int checkPow2Parameter(String name, int actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual != 0 && Integer.bitCount(actual) != 1) throw Messages.log.paramNotPow2(name); + return actual; + } + + /** + * @hidden + */ + public static void checkPow2Parameter$$bridge(String name, int actual) throws IllegalArgumentException { + checkPow2Parameter(name, actual); } /** @@ -475,12 +614,21 @@ public static void checkPow2Parameter(String name, int actual) throws IllegalArg * * @param name the parameter name * @param actual the actual parameter value + * @return the given actual value * @throws IllegalArgumentException if the actual value is not zero or a power of two */ - public static void checkPow2Parameter(String name, long actual) throws IllegalArgumentException { + public static long checkPow2Parameter(String name, long actual) throws IllegalArgumentException { checkNotNullParamChecked("name", name); if (actual != 0 && Long.bitCount(actual) != 1) throw Messages.log.paramNotPow2(name); + return actual; + } + + /** + * @hidden + */ + public static void checkPow2Parameter$$bridge(String name, long actual) throws IllegalArgumentException { + checkPow2Parameter(name, actual); } /** diff --git a/pom.xml b/pom.xml index 1101e564..1ee63a32 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ Common utilities for SmallRye + 1.6.Final 2.1 0.103.1 1.2.3 @@ -182,6 +183,20 @@ + + org.jboss.bridger + bridger + ${version.bridger} + + + bridger + process-classes + + transform + + + +