jdk/src/java.base/share/classes/java/lang/VersionProps.java.template
changeset 39648 9bbd1300c256
parent 39314 779f1d11a746
child 40192 64c0b3d47afb
equal deleted inserted replaced
39647:cd5deb6026dd 39648:9bbd1300c256
    65         System.setProperty("java.version", java_version);
    65         System.setProperty("java.version", java_version);
    66         System.setProperty("java.runtime.version", java_runtime_version);
    66         System.setProperty("java.runtime.version", java_runtime_version);
    67         System.setProperty("java.runtime.name", java_runtime_name);
    67         System.setProperty("java.runtime.name", java_runtime_name);
    68     }
    68     }
    69 
    69 
       
    70     private static int parseVersionNumber(String version, int prevIndex, int index) {
       
    71         if (index - prevIndex > 1 &&
       
    72             Character.digit(version.charAt(prevIndex), 10) <= 0)
       
    73             throw new IllegalArgumentException("Leading zeros not supported (" +
       
    74                     version.substring(prevIndex, index) + ")");
       
    75         return Integer.parseInt(version, prevIndex, index, 10);
       
    76     }
       
    77 
       
    78     // This method is reflectively used by regression tests.
       
    79     static List<Integer> parseVersionNumbers(String version) {
       
    80         List<Integer> verNumbers = new ArrayList<>(4);
       
    81         int prevIndex = 0;
       
    82         int index = version.indexOf('.');
       
    83         while (index > 0) {
       
    84             verNumbers.add(parseVersionNumber(version, prevIndex, index));
       
    85             prevIndex = index + 1; // Skip the period
       
    86             index = version.indexOf('.', prevIndex);
       
    87         }
       
    88         verNumbers.add(parseVersionNumber(version, prevIndex, version.length()));
       
    89 
       
    90         if (verNumbers.get(0) == 0 || verNumbers.get(verNumbers.size() - 1) == 0)
       
    91             throw new IllegalArgumentException("Leading/trailing zeros not supported (" +
       
    92                     verNumbers + ")");
       
    93 
       
    94         return verNumbers;
       
    95     }
       
    96 
    70     static List<Integer> versionNumbers() {
    97     static List<Integer> versionNumbers() {
    71         List<Integer> versionNumbers = new ArrayList<>(4);
    98         return parseVersionNumbers(VERSION_NUMBER);
    72         int prevIndex = 0;
       
    73         int index = VERSION_NUMBER.indexOf('.');
       
    74         while (index > 0) {
       
    75             versionNumbers.add(
       
    76                     Integer.parseInt(VERSION_NUMBER, prevIndex, index, 10));
       
    77             prevIndex = index + 1; // Skip the period
       
    78             index = VERSION_NUMBER.indexOf('.', prevIndex);
       
    79         }
       
    80         versionNumbers.add(Integer.parseInt(VERSION_NUMBER,
       
    81                 prevIndex, VERSION_NUMBER.length(), 10));
       
    82         return versionNumbers;
       
    83     }
    99     }
    84 
   100 
    85     static Optional<String> pre() {
   101     static Optional<String> pre() {
    86         return optionalOf(VERSION_PRE);
   102         return optionalOf(VERSION_PRE);
    87     }
   103     }