Author: fanningpj
Date: Tue Jul 21 09:49:02 2026
New Revision: 1936419
Log:
throw loader exception on repeated string in StringPool.readFrom. Thanks to
aizu-m. This closes #88
Modified:
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
xmlbeans/trunk/src/test/java/org/apache/xmlbeans/impl/schema/StringPoolCodeTest.java
Modified:
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
==============================================================================
---
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
Tue Jul 21 08:50:06 2026 (r1936418)
+++
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
Tue Jul 21 09:49:02 2026 (r1936419)
@@ -725,7 +725,7 @@ public class SchemaTypeSystemImpl extend
String str = input.readLongUTF().intern();
int code = codeForString(str);
if (code != i) {
- throw new IllegalStateException();
+ throw new SchemaTypeLoaderException("Repeated string
pool entry", _name, _handle,
SchemaTypeLoaderException.UNRECOGNIZED_INDEX_ENTRY);
}
}
} catch (IOException e) {
Modified:
xmlbeans/trunk/src/test/java/org/apache/xmlbeans/impl/schema/StringPoolCodeTest.java
==============================================================================
---
xmlbeans/trunk/src/test/java/org/apache/xmlbeans/impl/schema/StringPoolCodeTest.java
Tue Jul 21 08:50:06 2026 (r1936418)
+++
xmlbeans/trunk/src/test/java/org/apache/xmlbeans/impl/schema/StringPoolCodeTest.java
Tue Jul 21 09:49:02 2026 (r1936419)
@@ -15,8 +15,14 @@
package org.apache.xmlbeans.impl.schema;
import org.apache.xmlbeans.SchemaTypeLoaderException;
+import org.apache.xmlbeans.impl.util.LongUTFDataInputStream;
+import org.apache.xmlbeans.impl.util.LongUTFDataOutputStream;
import org.junit.jupiter.api.Test;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -43,4 +49,22 @@ public class StringPoolCodeTest {
// marker, so a negative code can reach stringForCode
assertThrows(SchemaTypeLoaderException.class, () ->
pool.stringForCode(-1));
}
+
+ @Test
+ void readFromRejectsRepeatedEntry() throws IOException {
+ // craft a string pool section that declares three entries but repeats
a
+ // string; codeForString hands back the earlier code, so code != i in
the
+ // populate loop, which must surface as the documented loader exception
+ // rather than a bare IllegalStateException
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ LongUTFDataOutputStream out = new LongUTFDataOutputStream(bos);
+ out.writeShortOrInt(3);
+ out.writeLongUTF("dup");
+ out.writeLongUTF("dup");
+ out.flush();
+
+ SchemaTypeSystemImpl.StringPool pool = new
SchemaTypeSystemImpl.StringPool("handle", "name");
+ LongUTFDataInputStream in = new LongUTFDataInputStream(new
ByteArrayInputStream(bos.toByteArray()));
+ assertThrows(SchemaTypeLoaderException.class, () -> pool.readFrom(in));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]