Skip to content

Commit

Permalink
8327261: Parsing test for Double/Float succeeds w/o testing all bad c…
Browse files Browse the repository at this point in the history
…ases

Reviewed-by: darcy, gli, joehw, jlu, bpb, lancea
  • Loading branch information
naotoj committed Mar 6, 2024
1 parent 08b03a3 commit 9f70940
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
21 changes: 9 additions & 12 deletions test/jdk/java/lang/Double/ParseDouble.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -556,24 +556,21 @@ private static void rudimentaryTest() {
*/
private static void testParsing(String [] input,
boolean exceptionalInput) {
for(int i = 0; i < input.length; i++) {
double d;

for (String s : input) {
try {
d = Double.parseDouble(input[i]);
check(input[i]);
}
catch (NumberFormatException e) {
if (! exceptionalInput) {
Double.parseDouble(s);
check(s);
} catch (NumberFormatException e) {
if (!exceptionalInput) {
throw new RuntimeException("Double.parseDouble rejected " +
"good string `" + input[i] +
"good string `" + s +
"'.");
}
break;
continue;
}
if (exceptionalInput) {
throw new RuntimeException("Double.parseDouble accepted " +
"bad string `" + input[i] +
"bad string `" + s +
"'.");
}
}
Expand Down
21 changes: 9 additions & 12 deletions test/jdk/java/lang/Float/ParseFloat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -276,24 +276,21 @@ private static void rudimentaryTest() {
*/
private static void testParsing(String [] input,
boolean exceptionalInput) {
for(int i = 0; i < input.length; i++) {
double d;

for (String s : input) {
try {
d = Float.parseFloat(input[i]);
check(input[i]);
}
catch (NumberFormatException e) {
if (! exceptionalInput) {
Float.parseFloat(s);
check(s);
} catch (NumberFormatException e) {
if (!exceptionalInput) {
throw new RuntimeException("Float.parseFloat rejected " +
"good string `" + input[i] +
"good string `" + s +
"'.");
}
break;
continue;
}
if (exceptionalInput) {
throw new RuntimeException("Float.parseFloat accepted " +
"bad string `" + input[i] +
"bad string `" + s +
"'.");
}
}
Expand Down

3 comments on commit 9f70940

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 9f70940 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 9f70940 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-9f709407 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 9f709407 from the openjdk/jdk repository.

The commit being backported was authored by Naoto Sato on 6 Mar 2024 and was reviewed by Joe Darcy, Guoxiong Li, Joe Wang, Justin Lu, Brian Burkhalter and Lance Andersen.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-9f709407:backport-GoeLin-9f709407
$ git checkout backport-GoeLin-9f709407
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-GoeLin-9f709407

Please sign in to comment.