1
1
/*
2
- * Copyright (c) 2004, 2018 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2004, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/*
25
25
* @test
26
- * @bug 4984872
26
+ * @bug 4984872 8318915
27
27
* @summary Basic tests of toPlainString method
28
28
* @run main ToPlainStringTests
29
29
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+EliminateAutoBox -XX:AutoBoxCacheMax=20000 ToPlainStringTests
@@ -67,6 +67,11 @@ public static void main(String argv[]) {
67
67
{"12345678901234567890" , "12345678901234567890" },
68
68
{"12345678901234567890e22" , "123456789012345678900000000000000000000000" },
69
69
{"12345678901234567890e-22" , "0.0012345678901234567890" },
70
+
71
+ {"12345e-1" , "1234.5" },
72
+ {"12345e-2" , "123.45" },
73
+ {"12345e-3" , "12.345" },
74
+ {"12345e-4" , "1.2345" },
70
75
};
71
76
72
77
int errors = 0 ;
@@ -89,6 +94,38 @@ public static void main(String argv[]) {
89
94
}
90
95
}
91
96
97
+ String [] failingCases = {
98
+ "1E-" + (Integer .MAX_VALUE - 0 ), // MAX_VALUE + 2 chars
99
+ "1E-" + (Integer .MAX_VALUE - 1 ), // MAX_VALUE + 1 chars
100
+
101
+ "-1E-" + (Integer .MAX_VALUE - 0 ), // MAX_VALUE + 3 chars
102
+ "-1E-" + (Integer .MAX_VALUE - 1 ), // MAX_VALUE + 2 chars
103
+ "-1E-" + (Integer .MAX_VALUE - 2 ), // MAX_VALUE + 1 chars
104
+
105
+ "123456789E-" + (Integer .MAX_VALUE - 0 ), // MAX_VALUE + 2 chars
106
+ "123456789E-" + (Integer .MAX_VALUE - 1 ), // MAX_VALUE + 1 chars
107
+
108
+ "-123456789E-" + (Integer .MAX_VALUE - 0 ), // MAX_VALUE + 3 chars
109
+ "-123456789E-" + (Integer .MAX_VALUE - 1 ), // MAX_VALUE + 2 chars
110
+ "-123456789E-" + (Integer .MAX_VALUE - 2 ), // MAX_VALUE + 1 chars
111
+
112
+ "1E" + Integer .MAX_VALUE , // MAX_VALUE + 1 chars
113
+ "123456789E" + Integer .MAX_VALUE , // MAX_VALUE + 9 chars
114
+
115
+ "-1E" + Integer .MAX_VALUE , // MAX_VALUE + 2 chars
116
+ "-123456789E" + Integer .MAX_VALUE , // MAX_VALUE + 10 chars
117
+ };
118
+ /* We expect pre-emptive OutOfMemoryErrors, nothing else */
119
+ for (String failingCase : failingCases ) {
120
+ try {
121
+ new BigDecimal (failingCase ).toPlainString ();
122
+ } catch (OutOfMemoryError expected ) {
123
+ continue ;
124
+ } catch (Throwable ignored ) {
125
+ }
126
+ ++errors ;
127
+ }
128
+
92
129
if (errors > 0 )
93
130
throw new RuntimeException (errors + " errors during run." );
94
131
}
0 commit comments