groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8824) CLONE - Wrong detection of Java 10 version in groovy-json Part 2
Date Fri, 05 Oct 2018 04:31:00 GMT

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

Paul King updated GROOVY-8824:
------------------------------
    Description: 
I cloned the issue to cater for testing. I didn't get time to look at refactoring just yet.

ORIGINAL BELOW:

The following code from {{groovy.json.internal.Sys}} incorrectly parses {{java.version}} property
on newer Java-s:
{code:java}
    static {
        BigDecimal v = new BigDecimal("-1");
        String sversion = System.getProperty("java.version");
        if (sversion.indexOf("_") != -1) {
            final String[] split = sversion.split("_");
            try {
                String ver = split[0];

                if (ver.startsWith("1.7")) {
                    v = new BigDecimal("1.7");
                }

                if (ver.startsWith("1.8")) {
                    v = new BigDecimal("1.8");
                }

                if (ver.startsWith("1.9")) {
                    v = new BigDecimal("1.9");
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                System.err.println("Unable to determine build number or version");
            }
        } else if ("1.8.0".equals(sversion)) {
            v = new BigDecimal("1.8");
        } else {
            Pattern p = Pattern.compile("^([1-9]\\.[0-9]+)");
            Matcher matcher = p.matcher(sversion);
            if (matcher.find()) {
                v = new BigDecimal(matcher.group(0));
            }
        }

        is1_8OrLater = v.compareTo(new BigDecimal("1.8")) >= 0;
        is1_7 = v.compareTo(new BigDecimal("1.7")) == 0;
        is1_8 = v.compareTo(new BigDecimal("1.8")) == 0;
    }
{code}
Under Java 10+ ({{java.version=10.0.2}}) all {{is*}} fields are set to {{false}}.

The outcome of it is e.g. {{LazyMap}} to use {{j.u.TreeMap}} instead of {{j.u.LinkedHashMap}}
that would give insertion order for maps returned from {{JsonSlurper}}.

Just extending the pattern to 
{code:java}
"^([1-9]+\\.[0-9]+)"
{code}
seems to do the job.

  was:
I cloned the issue to cater for testing. I didn't get time to look at refactoring just yet.

The following code from {{groovy.json.internal.Sys}} incorrectly parses {{java.version}} property
on newer Java-s:
{code:java}
    static {
        BigDecimal v = new BigDecimal("-1");
        String sversion = System.getProperty("java.version");
        if (sversion.indexOf("_") != -1) {
            final String[] split = sversion.split("_");
            try {
                String ver = split[0];

                if (ver.startsWith("1.7")) {
                    v = new BigDecimal("1.7");
                }

                if (ver.startsWith("1.8")) {
                    v = new BigDecimal("1.8");
                }

                if (ver.startsWith("1.9")) {
                    v = new BigDecimal("1.9");
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                System.err.println("Unable to determine build number or version");
            }
        } else if ("1.8.0".equals(sversion)) {
            v = new BigDecimal("1.8");
        } else {
            Pattern p = Pattern.compile("^([1-9]\\.[0-9]+)");
            Matcher matcher = p.matcher(sversion);
            if (matcher.find()) {
                v = new BigDecimal(matcher.group(0));
            }
        }

        is1_8OrLater = v.compareTo(new BigDecimal("1.8")) >= 0;
        is1_7 = v.compareTo(new BigDecimal("1.7")) == 0;
        is1_8 = v.compareTo(new BigDecimal("1.8")) == 0;
    }
{code}
Under Java 10+ ({{java.version=10.0.2}}) all {{is*}} fields are set to {{false}}.

The outcome of it is e.g. {{LazyMap}} to use {{j.u.TreeMap}} instead of {{j.u.LinkedHashMap}}
that would give insertion order for maps returned from {{JsonSlurper}}.

Just extending the pattern to 
{code:java}
"^([1-9]+\\.[0-9]+)"
{code}
seems to do the job.


> CLONE - Wrong detection of Java 10 version in groovy-json Part 2
> ----------------------------------------------------------------
>
>                 Key: GROOVY-8824
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8824
>             Project: Groovy
>          Issue Type: Bug
>          Components: JSON
>    Affects Versions: 3.x, 2.5.2
>         Environment: Oracle Java SE 10, Linux
>            Reporter: Przemek Wesolek
>            Assignee: Paul King
>            Priority: Major
>
> I cloned the issue to cater for testing. I didn't get time to look at refactoring just
yet.
> ORIGINAL BELOW:
> The following code from {{groovy.json.internal.Sys}} incorrectly parses {{java.version}}
property on newer Java-s:
> {code:java}
>     static {
>         BigDecimal v = new BigDecimal("-1");
>         String sversion = System.getProperty("java.version");
>         if (sversion.indexOf("_") != -1) {
>             final String[] split = sversion.split("_");
>             try {
>                 String ver = split[0];
>                 if (ver.startsWith("1.7")) {
>                     v = new BigDecimal("1.7");
>                 }
>                 if (ver.startsWith("1.8")) {
>                     v = new BigDecimal("1.8");
>                 }
>                 if (ver.startsWith("1.9")) {
>                     v = new BigDecimal("1.9");
>                 }
>             } catch (Exception ex) {
>                 ex.printStackTrace();
>                 System.err.println("Unable to determine build number or version");
>             }
>         } else if ("1.8.0".equals(sversion)) {
>             v = new BigDecimal("1.8");
>         } else {
>             Pattern p = Pattern.compile("^([1-9]\\.[0-9]+)");
>             Matcher matcher = p.matcher(sversion);
>             if (matcher.find()) {
>                 v = new BigDecimal(matcher.group(0));
>             }
>         }
>         is1_8OrLater = v.compareTo(new BigDecimal("1.8")) >= 0;
>         is1_7 = v.compareTo(new BigDecimal("1.7")) == 0;
>         is1_8 = v.compareTo(new BigDecimal("1.8")) == 0;
>     }
> {code}
> Under Java 10+ ({{java.version=10.0.2}}) all {{is*}} fields are set to {{false}}.
> The outcome of it is e.g. {{LazyMap}} to use {{j.u.TreeMap}} instead of {{j.u.LinkedHashMap}}
that would give insertion order for maps returned from {{JsonSlurper}}.
> Just extending the pattern to 
> {code:java}
> "^([1-9]+\\.[0-9]+)"
> {code}
> seems to do the job.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message