[ 
https://issues.apache.org/jira/browse/SHIRO-545?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ariel Isaac updated SHIRO-545:
------------------------------
    Description: 
If Shiro is running in Java 8 it assumes that the major version is 1.3, because 
this case it's not included in the if blocks and goes to the default version 
which is 1.3, also the " if (version.indexOf("1.7.") != -1) {" should be 
contains, instead of indexOf, contains is highly more readable, so the code 
should be something like 


/**
     * Constant identifying the 1.8 JVM.
     */
    public static final int JAVA_18 = 5;
    /** The virtual machine version, i.e. 
<code>System.getProperty("java.version");</code>. */
    private static final String version;

    /**
     * The virtual machine <em>major</em> version.  For example, with a 
<code>version</code> of
     * <code>1.5.6_10</code>, this would be <code>1.5</code>
     */
    private static final int majorVersion;

    /**
     * Static code initialization block that sets the
     * <code>version</code> and <code>majorVersion</code> Class constants
     * upon initialization.
     */
    static {

        version = System.getProperty("java.version");

        // version String should look like "1.4.2_10"

        if (version.contains("1.8.")) {

            majorVersion = JAVA_18;

        } else if (version.contains("1.7")){

            majorVersion = JAVA_17;

        } else if (version.contains("1.6.")) {

            majorVersion = JAVA_16;

        } else if (version.contains("1.5.")) {

            majorVersion = JAVA_15;

        } else if (version.contains("1.4.")) {

            majorVersion = JAVA_14;

        } else {

            // else leave 1.3 as default (it's either 1.3 or unknown)

            majorVersion = JAVA_13;

        }

    }

  was:
If Shiro is running in Java 8 it assumes that the major version is 1.3, because 
this case it's not included in the if blocks and goes to the default version 
which is 1.3, also the " if (version.indexOf("1.7.") != -1) {" should be 
contains, instead of indexOf, contains is highly more readable, so the code 
should be something like 


/**
     * Constant identifying the 1.8 JVM.
     */
    public static final int JAVA_18 = 5;
    /** The virtual machine version, i.e. 
<code>System.getProperty("java.version");</code>. */
    private static final String version;

    /**
     * The virtual machine <em>major</em> version.  For example, with a 
<code>version</code> of
     * <code>1.5.6_10</code>, this would be <code>1.5</code>
     */
    private static final int majorVersion;

    /**
     * Static code initialization block that sets the
     * <code>version</code> and <code>majorVersion</code> Class constants
     * upon initialization.
     */
    static {
        version = System.getProperty("java.version");
        // version String should look like "1.4.2_10"
        if (version.contains("1.8.")) {
            majorVersion = JAVA_18;
        } else if (version.contains("1.7")){
            majorVersion = JAVA_17;
        } else if (version.contains("1.6.")) {
            majorVersion = JAVA_16;
        } else if (version.contains("1.5.")) {
            majorVersion = JAVA_15;
        } else if (version.contains("1.4.")) {
            majorVersion = JAVA_14;
        } else {
            // else leave 1.3 as default (it's either 1.3 or unknown)
            majorVersion = JAVA_13;
        }
    }


> JavaEnvironment version getter
> ------------------------------
>
>                 Key: SHIRO-545
>                 URL: https://issues.apache.org/jira/browse/SHIRO-545
>             Project: Shiro
>          Issue Type: Bug
>          Components: Cryptography & Hashing
>    Affects Versions: 1.2.4
>         Environment: Java 8
>            Reporter: Ariel Isaac
>            Priority: Minor
>              Labels: easyfix, newbie, patch
>             Fix For: 1.3.0, 2.0.0, 1.2.5
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> If Shiro is running in Java 8 it assumes that the major version is 1.3, 
> because this case it's not included in the if blocks and goes to the default 
> version which is 1.3, also the " if (version.indexOf("1.7.") != -1) {" should 
> be contains, instead of indexOf, contains is highly more readable, so the 
> code should be something like 
> /**
>      * Constant identifying the 1.8 JVM.
>      */
>     public static final int JAVA_18 = 5;
>     /** The virtual machine version, i.e. 
> <code>System.getProperty("java.version");</code>. */
>     private static final String version;
>     /**
>      * The virtual machine <em>major</em> version.  For example, with a 
> <code>version</code> of
>      * <code>1.5.6_10</code>, this would be <code>1.5</code>
>      */
>     private static final int majorVersion;
>     /**
>      * Static code initialization block that sets the
>      * <code>version</code> and <code>majorVersion</code> Class constants
>      * upon initialization.
>      */
>     static {
>         version = System.getProperty("java.version");
>         // version String should look like "1.4.2_10"
>         if (version.contains("1.8.")) {
>             majorVersion = JAVA_18;
>         } else if (version.contains("1.7")){
>             majorVersion = JAVA_17;
>         } else if (version.contains("1.6.")) {
>             majorVersion = JAVA_16;
>         } else if (version.contains("1.5.")) {
>             majorVersion = JAVA_15;
>         } else if (version.contains("1.4.")) {
>             majorVersion = JAVA_14;
>         } else {
>             // else leave 1.3 as default (it's either 1.3 or unknown)
>             majorVersion = JAVA_13;
>         }
>     }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to