Skip to content

Commit

Permalink
Fix reflective access of Runtime.version().major()
Browse files Browse the repository at this point in the history
	Change on 2017/10/13 by cushon <cushon@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172178078
  • Loading branch information
cushon authored and tomball committed Oct 18, 2017
1 parent 9ec70eb commit c025bff
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -75,10 +75,10 @@ public static boolean java9Minimum(SourceVersion sourceVersion) {
*/
public static SourceVersion defaultVersion() {
try {
Class<?> versionClass = Class.forName("java.lang.Runtime.Version");
Method m = versionClass.getMethod("major");
Integer majorVersion = (Integer) m.invoke(null);
return SourceVersion.valueOf(majorVersion.intValue());
Method versionMethod = Runtime.class.getMethod("version");
Object version = versionMethod.invoke(null);
int majorVersion = (int) version.getClass().getMethod("major").invoke(version);
return SourceVersion.valueOf(majorVersion);
} catch (Exception e) {
SourceVersion sysVer = SourceVersion.parse(System.getProperty("java.specification.version"));
// TODO(tball): remove when Java 9 source is supported.
Expand Down

0 comments on commit c025bff

Please sign in to comment.