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

Backport-of: 9f7094079b6eb6b60b345955dba358a2d5c90931
  • Loading branch information
GoeLin committed Mar 25, 2024
1 parent 660c00a commit c33815a
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

1 comment on commit c33815a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.