From 12b79f736fdab55c6a37657a8ec606683768cee1 Mon Sep 17 00:00:00 2001 From: "Gerlach, Winfried" Date: Wed, 12 Nov 2025 07:15:04 +0100 Subject: [PATCH 1/2] fix wrong length calculation in IntData --- .../v2/runtime/unmarshaller/IntData.java | 4 ++-- .../v2/runtime/unmarshaller/IntDataTest.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 jaxb-ri/runtime/impl/src/test/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntDataTest.java diff --git a/jaxb-ri/runtime/impl/src/main/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntData.java b/jaxb-ri/runtime/impl/src/main/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntData.java index 48514794c..13f2fbd7e 100644 --- a/jaxb-ri/runtime/impl/src/main/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntData.java +++ b/jaxb-ri/runtime/impl/src/main/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntData.java @@ -47,8 +47,8 @@ public void reset(int i) { length = (i < 0) ? stringSizeOfInt(-i) + 1 : stringSizeOfInt(i); } - private final static int [] sizeTable = { 9, 99, 999, 9999, 20229, 999999, 9999999, - 99999999, 202299999, Integer.MAX_VALUE }; + private static final int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999, + 99999999, 999999999, Integer.MAX_VALUE }; // Requires positive x private static int stringSizeOfInt(int x) { diff --git a/jaxb-ri/runtime/impl/src/test/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntDataTest.java b/jaxb-ri/runtime/impl/src/test/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntDataTest.java new file mode 100644 index 000000000..750574a14 --- /dev/null +++ b/jaxb-ri/runtime/impl/src/test/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntDataTest.java @@ -0,0 +1,20 @@ +package org.glassfish.jaxb.runtime.v2.runtime.unmarshaller; + +import org.junit.Test; +import org.junit.Assert; + +public class IntDataTest { + + @Test + public void testLength() { + IntData data = new IntData(); + data.reset(54321); + Assert.assertEquals(5, data.length()); + data.reset(-54321); + Assert.assertEquals(6, data.length()); + data.reset(987654321); + Assert.assertEquals(9, data.length()); + data.reset(-987654321); + Assert.assertEquals(10, data.length()); + } +} \ No newline at end of file From 964410514347ec0769dda6a6a55dce7b6dca7b59 Mon Sep 17 00:00:00 2001 From: "Gerlach, Winfried" Date: Wed, 12 Nov 2025 10:08:37 +0100 Subject: [PATCH 2/2] changes from code review --- .../runtime/v2/runtime/unmarshaller/IntData.java | 3 ++- .../runtime/v2/runtime/unmarshaller/IntDataTest.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/jaxb-ri/runtime/impl/src/main/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntData.java b/jaxb-ri/runtime/impl/src/main/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntData.java index 13f2fbd7e..23a583c1a 100644 --- a/jaxb-ri/runtime/impl/src/main/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntData.java +++ b/jaxb-ri/runtime/impl/src/main/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntData.java @@ -1,5 +1,6 @@ /* * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025 Contributors to the Eclipse Foundation. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -23,7 +24,7 @@ public class IntData extends Pcdata { /** * The int value that this {@link Pcdata} represents. - * + *

* Modifiable. */ private int data; diff --git a/jaxb-ri/runtime/impl/src/test/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntDataTest.java b/jaxb-ri/runtime/impl/src/test/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntDataTest.java index 750574a14..90ed072bf 100644 --- a/jaxb-ri/runtime/impl/src/test/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntDataTest.java +++ b/jaxb-ri/runtime/impl/src/test/java/org/glassfish/jaxb/runtime/v2/runtime/unmarshaller/IntDataTest.java @@ -1,3 +1,13 @@ +/* + * Copyright (c) 2025 Contributors to the Eclipse Foundation. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0, which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + package org.glassfish.jaxb.runtime.v2.runtime.unmarshaller; import org.junit.Test; @@ -17,4 +27,4 @@ public void testLength() { data.reset(-987654321); Assert.assertEquals(10, data.length()); } -} \ No newline at end of file +}