Skip to content

Commit

Permalink
HV-1048 Fix validator to make to work on JDK9 with project Verona
Browse files Browse the repository at this point in the history
  • Loading branch information
ctomc authored and hferentschik committed Jan 22, 2016
1 parent 99a6487 commit 0359027
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
*/
package org.hibernate.validator.internal.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.hibernate.validator.internal.util.logging.LoggerFactory;

/**
* @author Hardy Ferentschik
* @author Kevin Pollet <kevin.pollet@serli.com> (C) 2012 SERLI
*/
public final class Version {
private static final Pattern JAVA_VERSION_PATTERN = Pattern.compile( "^(?:1\\.)?(\\d+)$" );
static {
LoggerFactory.make().version( getVersionString() );
}
Expand All @@ -30,10 +34,18 @@ public static void touch() {
* @return the Java release as an integer (e.g. 8 for Java 8)
*/
public static int getJavaRelease() {
// Will return something like 1.8
String[] specificationVersion = System.getProperty( "java.specification.version" ).split( "\\." );
// Will return something like 1.8 or 9
String vmVersionStr = System.getProperty( "java.specification.version" );

Matcher matcher = JAVA_VERSION_PATTERN.matcher( vmVersionStr ); //match 1.<number> or <number>

if ( matcher.find() ) {
return Integer.valueOf( matcher.group( 1 ) );
}
else {
throw new RuntimeException("Unknown version of jvm " + vmVersionStr);
}

return Integer.parseInt( specificationVersion[1] );
}

// helper class should not have a public constructor
Expand Down

0 comments on commit 0359027

Please sign in to comment.