Skip to content

Commit

Permalink
Introduce JRE.MINIMUM_VERSION constant
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Feb 3, 2025
1 parent a3716e6 commit 7c60b6f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ protected void validateVersions(JRE[] jres, int[] versions) {
() -> "JRE.UNDEFINED is not supported in @" + this.annotationName);
}
for (int version : versions) {
Preconditions.condition(version >= 8,
() -> String.format("Version [%d] in @%s must be greater than or equal to 8", version,
this.annotationName));
Preconditions.condition(version >= JRE.MINIMUM_VERSION,
() -> String.format("Version [%d] in @%s must be greater than or equal to %d", version,
this.annotationName, JRE.MINIMUM_VERSION));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ static boolean isCurrentVersionWithinRange(String annotationName, JRE minJre, JR
annotationName));

// Users must supply valid values for minVersion and maxVersion.
Preconditions.condition(!minVersionSet || (minVersion >= 8),
() -> String.format("@%s's minVersion [%d] must be greater than or equal to 8", annotationName,
minVersion));
Preconditions.condition(!maxVersionSet || (maxVersion >= 8),
() -> String.format("@%s's maxVersion [%d] must be greater than or equal to 8", annotationName,
maxVersion));
Preconditions.condition(!minVersionSet || (minVersion >= JRE.MINIMUM_VERSION),
() -> String.format("@%s's minVersion [%d] must be greater than or equal to %d", annotationName, minVersion,
JRE.MINIMUM_VERSION));
Preconditions.condition(!maxVersionSet || (maxVersion >= JRE.MINIMUM_VERSION),
() -> String.format("@%s's maxVersion [%d] must be greater than or equal to %d", annotationName, maxVersion,
JRE.MINIMUM_VERSION));

// Now that we have checked the basic preconditions, we need to ensure that we are
// using valid JRE enum constants.
Expand All @@ -72,10 +72,11 @@ static boolean isCurrentVersionWithinRange(String annotationName, JRE minJre, JR
int max = (maxVersionSet ? maxVersion : maxJre.version());

// Finally, we need to validate the effective minimum and maximum values.
Preconditions.condition((min != 8 || max != Integer.MAX_VALUE),
Preconditions.condition((min != JRE.MINIMUM_VERSION || max != Integer.MAX_VALUE),
() -> "You must declare a non-default value for the minimum or maximum value in @" + annotationName);
Preconditions.condition(min >= 8,
() -> String.format("@%s's minimum value [%d] must greater than or equal to 8", annotationName, min));
Preconditions.condition(min >= JRE.MINIMUM_VERSION,
() -> String.format("@%s's minimum value [%d] must greater than or equal to %d", annotationName, min,
JRE.MINIMUM_VERSION));
Preconditions.condition(min <= max,
() -> String.format("@%s's minimum value [%d] must be less than or equal to its maximum value [%d]",
annotationName, min, max));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public enum JRE {

static final int UNDEFINED_VERSION = -1;

static final int MINIMUM_VERSION = 8;

private static final Logger logger = LoggerFactory.getLogger(JRE.class);

private static final int CURRENT_VERSION = determineCurrentVersion();
Expand Down

0 comments on commit 7c60b6f

Please sign in to comment.