1 package org.slf4j.impl;
2
3 import java.lang.reflect.Method;
4
5 import org.slf4j.helpers.Util;
6
7 public class VersionUtil {
8 static final int MINIMAL_VERSION = 5;
9
10 static public int getJavaMajorVersion() {
11 String javaVersionString = Util.safeGetSystemProperty("java.version");
12 return getJavaMajorVersion(javaVersionString);
13 }
14
15 static int getJavaMajorVersion(String versionString) {
16 if (versionString == null)
17 return MINIMAL_VERSION;
18 if (versionString.startsWith("1.")) {
19 return versionString.charAt(2) - '0';
20 } else {
21
22 try {
23 Method versionMethod = Runtime.class.getMethod("version");
24 Object versionObj = versionMethod.invoke(null);
25 Method majorMethod = versionObj.getClass().getMethod("major");
26 Integer resultInteger = (Integer) majorMethod.invoke(versionObj);
27 return resultInteger.intValue();
28 } catch (Exception e) {
29 return MINIMAL_VERSION;
30 }
31 }
32 }
33 }