1
1
/*
2
- * Copyright (c) 2005, 2019 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2005, 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 6806261 8211936
26
+ * @bug 6806261 8211936 8305343
27
27
* @summary Tests of BigDecimal.longValueExact
28
28
*/
29
29
import java .math .*;
@@ -37,6 +37,7 @@ public static void main(String... args) {
37
37
38
38
failures += longValueExactSuccessful ();
39
39
failures += longValueExactExceptional ();
40
+ failures += longValueExactExceptional8305343 ();
40
41
41
42
if (failures > 0 ) {
42
43
throw new RuntimeException ("Incurred " + failures +
@@ -117,4 +118,27 @@ private static int longValueExactExceptional() {
117
118
}
118
119
return failures ;
119
120
}
121
+
122
+ private static int longValueExactExceptional8305343 () {
123
+ int failures = 0 ;
124
+ List <BigDecimal > exceptionalCases =
125
+ List .of (new BigDecimal ("1e" + (Integer .MAX_VALUE - 1 )),
126
+ new BigDecimal ("1e" + (Integer .MAX_VALUE ))
127
+ );
128
+
129
+ for (BigDecimal bd : exceptionalCases ) {
130
+ try {
131
+ bd .longValueExact ();
132
+ failures ++;
133
+ System .err .println ("Unexpected non-exceptional longValueExact on " + bd );
134
+ } catch (ArithmeticException e ) {
135
+ if (!e .getMessage ().toLowerCase ().contains ("overflow" )) {
136
+ failures ++;
137
+ System .err .println ("Unexpected non-exceptional longValueExact on " + bd );
138
+ }
139
+ }
140
+ }
141
+ return failures ;
142
+ }
143
+
120
144
}
0 commit comments