Modify

Opened 10 months ago

Closed 10 months ago

Last modified 10 months ago

#23124 closed defect (fixed)

java.lang.NumberFormatException for "openjdk 17.0.4.1" from Zulu

Reported by: hansfn Owned by: hansfn
Priority: minor Milestone: 23.08
Component: Core Version: tested
Keywords: template_report Cc:

Description (last modified by hansfn)

What steps will reproduce the problem?

  1. Launch JOSM

What is the expected result?

Start without error

What happens instead?

Starts normally with severe error:

2023-08-16 10:35:08.073 SEVERE: java.lang.NumberFormatException: For input string: "0.4"

The reason is that the version number consists of 4 integers separated by dots, not 3 as expected.

See line 1751 of Utils.java. I assume you could just count the dots and remove the last dot and integer.

Please provide any additional information below. Attach a screenshot if possible.

Relative:URL: ^/trunk
Repository:UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
Last:Changed Date: 2023-07-31 18:33:06 +0200 (Mon, 31 Jul 2023)
Revision:18789
Build-Date:2023-08-01 01:30:56
URL:https://josm.openstreetmap.de/svn/trunk

Identification: JOSM/1.5 (18789 en) Windows 10 64-Bit
OS Build number: Windows 10 Enterprise 2009 (19045)
Memory Usage: 119 MB / 494 MB (26 MB allocated, but free)
Java version: 17.0.4.1+1-LTS, Azul Systems, Inc., OpenJDK Client VM
Look and Feel: com.sun.java.swing.plaf.windows.WindowsLookAndFeel
Screen: \Display0 1920×1080 (scaling 1.25×1.25) \Display1 2560×1440 (scaling 1.00×1.00) \Display2 2560×1440 (scaling 1.00×1.00)
Maximum Screen Size: 2560×1440
Best cursor sizes: 16×16→32×32, 32×32→32×32
System property file.encoding: Cp1252
System property sun.jnu.encoding: Cp1252
Locale info: en_US
Numbers with default locale: 1234567890 -> 1234567890

Plugins:
+ conflation (0.6.11)
+ jts (36004)
+ todo (133)
+ utilsplugin2 (36097)

Validator rules:
+ http://osm.wzh.be/josm/different_buildings/buildings-import.validator.mapcss

Last errors/warnings:
- 00000.365 W: extended font config - overriding 'filename.Myanmar_Text=mmrtext.ttf' with 'MMRTEXT.TTF'
- 00000.366 W: extended font config - overriding 'filename.Mongolian_Baiti=monbaiti.ttf' with 'MONBAITI.TTF'
- 00002.423 W: Unable to request certificate of https://roottest-g3.pkioverheid.nl
- 00003.326 W: Unable to request certificate of https://roottest-g3.pkioverheid.nl
- 00007.847 E: java.lang.NumberFormatException: For input string: "0.4"

Attachments (0)

Change History (6)

comment:1 by hansfn, 10 months ago

Description: modified (diff)

comment:2 by taylor.smock, 10 months ago

Owner: changed from team to hansfn
Status: newneedinfo

I wasn't able to reproduce. Can you give us the actual stacktrace?

For reference, I wrote a test to try and reproduce, given your problem statement.

  • src/org/openstreetmap/josm/tools/Utils.java

    ---
    diff --git a/src/org/openstreetmap/josm/tools/Utils.java b/src/org/openstreetmap/josm/tools/Utils.java
    a b  
    17071707     * @since 12130
    17081708     */
    17091709    public static int getJavaVersion() {
    1710         String version = getSystemProperty("java.version");
     1710        return getJavaVersion(getSystemProperty("java.version"));
     1711    }
     1712
     1713    /**
     1714     * Returns the Java version as an int value
     1715     * @param version The Java version string
     1716     * @return the java version as an int value (8, 9, 10, etc.)
     1717     * @since xxx
     1718     */
     1719    static int getJavaVersion(String version) {
    17111720        if (version.startsWith("1.")) {
    17121721            version = version.substring(2);
    17131722        }
  • test/unit/org/openstreetmap/josm/tools/UtilsTest.java

    diff --git a/test/unit/org/openstreetmap/josm/tools/UtilsTest.java b/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    45import static org.junit.jupiter.api.Assertions.assertEquals;
    56import static org.junit.jupiter.api.Assertions.assertFalse;
    67import static org.junit.jupiter.api.Assertions.assertNull;
     
    2324
    2425import net.trajano.commons.testing.UtilityClassTestUtil;
    2526import org.junit.jupiter.api.Test;
     27import org.junit.jupiter.params.ParameterizedTest;
     28import org.junit.jupiter.params.provider.ValueSource;
    2629
    2730/**
    2831 * Unit tests of {@link Utils} class.
     
    544547        assertEquals(-1.0, Utils.getStandardDeviation(new double[]{}));
    545548        assertEquals(-1.0, Utils.getStandardDeviation(new double[]{0}));
    546549    }
     550
     551    /**
     552     * Some Java vendors have a fourth version specifier
     553     */
     554    @ParameterizedTest
     555    @ValueSource(strings = {"1.7", "1.8", "17", "17.0", "17.0.4", "17.0.4.1", "17.0.4.1+1-LTS"})
     556    void testNonRegression23124(String version) {
     557        final int versionNumber = assertDoesNotThrow(() -> Utils.getJavaVersion(version));
     558        switch (version) {
     559            case "1.7":
     560                assertEquals(7, versionNumber);
     561                break;
     562            case "1.8":
     563                assertEquals(8, versionNumber);
     564                break;
     565            default:
     566                assertEquals(17, versionNumber);
     567        }
     568    }
    547569}

comment:3 by hansfn, 10 months ago

Is it because you are testing getJavaVersion() instead of getJavaUpdate()? I linked to a line number and not the function so it's an easy mistake, but it's quite clear that version.substring(firstDotPos + 1, lastDotPos)will return "0.4" for "17.0.4.1".

comment:4 by taylor.smock, 10 months ago

OK. I was able to reproduce. Thanks for replying.

comment:5 by taylor.smock, 10 months ago

Resolution: fixed
Status: needinfoclosed

In 18811/josm:

Fix #23124: Azul Java 17.0.4.1 will cause a NumberFormatException

Java can have multiple dots instead of just two. Specifically, the Java version
specifier is $MAJOR.$MINOR.$SECURITY.$PATCH.

Previously, we assumed that there would only ever be two dots in the version
specifier, and got the first and last dot. Now we get the first and second dot.

In addition, this fixes some lint issues.

comment:6 by taylor.smock, 10 months ago

Milestone: 23.08

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain hansfn.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.