summaryrefslogtreecommitdiff
path: root/core/java14/com/vladium/util/IJREVersion.java
blob: 866c3febeb32f6043566bd7441d231fe5acf4900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
 * 
 * This program and the accompanying materials are made available under
 * the terms of the Common Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v10.html
 * 
 * $Id: IJREVersion.java,v 1.1.1.1.2.1 2004/07/10 03:34:52 vlad_r Exp $
 */
package com.vladium.util;

// ----------------------------------------------------------------------------
/**
 * A constant collection to detect the current JRE version. Note that this code
 * is more sophisticated then a mere check of "java.version" or "java.class.version"
 * and similar system properties because some JVMs allow overriding those
 * by the user (e.g., from the command line). This implementation relies on
 * the core classes only and tries to minimize the number of security-sensitive
 * methods it uses.<P>
 * 
 * This interface is supported in Java 1.1+ and should be compiled with class
 * version stamp 45.3 (-target 1.1).
 * 
 * @author Vlad Roubtsov, (C) 2003
 */
public
interface IJREVersion
{
    // public: ................................................................

    /** 'true' iff the current runtime version is 1.2 or later */
    boolean JRE_1_2_PLUS = _JREVersion._JRE_1_2_PLUS; // static final but not inlinable
    /** 'true' iff the current runtime version is 1.3 or later */
    boolean JRE_1_3_PLUS = _JREVersion._JRE_1_3_PLUS; // static final but not inlinable
    /** 'true' iff the current runtime version is 1.4 or later */
    boolean JRE_1_4_PLUS = _JREVersion._JRE_1_4_PLUS; // static final but not inlinable
    
    // supporting Java 1.5 is trivial...
    
    boolean JRE_SUN_SIGNAL_COMPATIBLE = _JREVersion._JRE_SUN_SIGNAL_COMPATIBLE;
    
    /*
     * Use a dummy nested class to fake a static initializer for the outer
     * interface (I want IJREVersion as an interface and not a class so that
     * all JRE_XXX constants could be imported via "implements").
     */
    abstract class _JREVersion
    {
        static final boolean _JRE_1_2_PLUS; // set in <clinit>
        static final boolean _JRE_1_3_PLUS; // set in <clinit>    
        static final boolean _JRE_1_4_PLUS; // set in <clinit>
        
        static final boolean _JRE_SUN_SIGNAL_COMPATIBLE; // set in <clinit>
        
        private _JREVersion () {} // prevent subclassing
    
        static
        {
            _JRE_1_2_PLUS = ((SecurityManager.class.getModifiers () & 0x0400) == 0);

            boolean temp = false;            
            if (_JRE_1_2_PLUS)
            {
                try
                {
                    StrictMath.abs (1.0);
                    temp = true;
                }
                catch (Error ignore) {}
            }
            _JRE_1_3_PLUS = temp;
            
            if (temp)
            {
                temp = false;
                try
                {
                    " ".subSequence (0, 0);
                    temp = true;
                }
                catch (NoSuchMethodError ignore) {}
            }
            _JRE_1_4_PLUS = temp;
            
            temp = false;
            try
            {
                Class.forName ("sun.misc.Signal");
                Class.forName ("sun.misc.SignalHandler");
                
                temp = true;
            }
            catch (Throwable ignore) {}
            
            _JRE_SUN_SIGNAL_COMPATIBLE = temp;
        }

    } // end of nested class

} // end of interface
// ----------------------------------------------------------------------------