Skip to content

Commit 121cc8e

Browse files
fix wrong length calculation in IntData (#1875)
* fix wrong length calculation in IntData * changes from code review
1 parent 5378461 commit 121cc8e

File tree

2 files changed

+34
-3
lines changed
  • jaxb-ri/runtime/impl/src
    • main/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller
    • test/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller

2 files changed

+34
-3
lines changed

jaxb-ri/runtime/impl/src/main/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntData.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2025 Contributors to the Eclipse Foundation. All rights reserved.
34
*
45
* This program and the accompanying materials are made available under the
56
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -23,7 +24,7 @@
2324
public class IntData extends Pcdata {
2425
/**
2526
* The int value that this {@link Pcdata} represents.
26-
*
27+
* <p>
2728
* Modifiable.
2829
*/
2930
private int data;
@@ -47,8 +48,8 @@ public void reset(int i) {
4748
length = (i < 0) ? stringSizeOfInt(-i) + 1 : stringSizeOfInt(i);
4849
}
4950

50-
private final static int [] sizeTable = { 9, 99, 999, 9999, 20229, 999999, 9999999,
51-
99999999, 202299999, Integer.MAX_VALUE };
51+
private static final int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
52+
99999999, 999999999, Integer.MAX_VALUE };
5253

5354
// Requires positive x
5455
private static int stringSizeOfInt(int x) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Distribution License v. 1.0, which is available at
6+
* http://www.eclipse.org/org/documents/edl-v10.php.
7+
*
8+
* SPDX-License-Identifier: BSD-3-Clause
9+
*/
10+
11+
package org.glassfish.jaxb.runtime.v2.runtime.unmarshaller;
12+
13+
import org.junit.Test;
14+
import org.junit.Assert;
15+
16+
public class IntDataTest {
17+
18+
@Test
19+
public void testLength() {
20+
IntData data = new IntData();
21+
data.reset(54321);
22+
Assert.assertEquals(5, data.length());
23+
data.reset(-54321);
24+
Assert.assertEquals(6, data.length());
25+
data.reset(987654321);
26+
Assert.assertEquals(9, data.length());
27+
data.reset(-987654321);
28+
Assert.assertEquals(10, data.length());
29+
}
30+
}

0 commit comments

Comments
 (0)