From c47ab5f6b72bd3ad6ab22f5461b4f24d4e816773 Mon Sep 17 00:00:00 2001 From: Marius Volkhart Date: Tue, 8 Dec 2020 20:43:42 +0000 Subject: [PATCH] 8256515: javax.xml.XMLEventReader produces incorrect START_DOCUMENT event Reviewed-by: joehw --- .../stream/events/StartDocumentEvent.java | 8 ++--- .../stream/events/XMLEventAllocatorImpl.java | 4 +-- .../XMLEventReaderTest/EventReaderTest.java | 29 +++++++++++++++++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/java.xml/share/classes/com/sun/xml/internal/stream/events/StartDocumentEvent.java b/src/java.xml/share/classes/com/sun/xml/internal/stream/events/StartDocumentEvent.java index 50950f6410a..32dfd3902fc 100644 --- a/src/java.xml/share/classes/com/sun/xml/internal/stream/events/StartDocumentEvent.java +++ b/src/java.xml/share/classes/com/sun/xml/internal/stream/events/StartDocumentEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -102,9 +102,9 @@ implements StartDocument { return fVersion; } - public void setStandalone(boolean flag) { - fStandaloneSet = true; - fStandalone = flag; + public void setStandalone(boolean isStandalone, boolean standaloneSet) { + fStandaloneSet = standaloneSet; + fStandalone = isStandalone; } public void setStandalone(String s) { diff --git a/src/java.xml/share/classes/com/sun/xml/internal/stream/events/XMLEventAllocatorImpl.java b/src/java.xml/share/classes/com/sun/xml/internal/stream/events/XMLEventAllocatorImpl.java index 5311cf20ee8..a1e920af023 100644 --- a/src/java.xml/share/classes/com/sun/xml/internal/stream/events/XMLEventAllocatorImpl.java +++ b/src/java.xml/share/classes/com/sun/xml/internal/stream/events/XMLEventAllocatorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -131,7 +131,7 @@ public class XMLEventAllocatorImpl implements XMLEventAllocator { } else { sdEvent.setDeclaredEncoding(false); } - sdEvent.setStandalone(streamReader.isStandalone()); + sdEvent.setStandalone(streamReader.isStandalone(), streamReader.standaloneSet()); sdEvent.setLocation(streamReader.getLocation()); event = sdEvent; break; diff --git a/test/jaxp/javax/xml/jaxp/unittest/stream/XMLEventReaderTest/EventReaderTest.java b/test/jaxp/javax/xml/jaxp/unittest/stream/XMLEventReaderTest/EventReaderTest.java index ccee3232bb0..af1ac977085 100644 --- a/test/jaxp/javax/xml/jaxp/unittest/stream/XMLEventReaderTest/EventReaderTest.java +++ b/test/jaxp/javax/xml/jaxp/unittest/stream/XMLEventReaderTest/EventReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,12 +28,18 @@ import java.util.NoSuchElementException; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.events.StartDocument; + +import org.testng.annotations.DataProvider; import org.testng.annotations.Listeners; import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; + /* * @test - * @bug 8204329 + * @bug 8204329 8256515 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest * @run testng stream.XMLEventReaderTest.EventReaderTest * @summary Tests XMLEventReader @@ -51,4 +57,23 @@ public class EventReaderTest { // no more event eventReader.nextEvent(); } + + @DataProvider + Object[][] standaloneSetTestData() { + return new Object[][]{ + {"", false, false}, + {"", false, true}, + {"", true, true} + }; + } + + @Test(dataProvider = "standaloneSetTestData") + void testStandaloneSet(String xml, boolean standalone, boolean standaloneSet) throws XMLStreamException { + XMLInputFactory factory = XMLInputFactory.newInstance(); + XMLEventReader reader = factory.createXMLEventReader(new StringReader(xml)); + StartDocument startDocumentEvent = (StartDocument) reader.nextEvent(); + + assertEquals(startDocumentEvent.isStandalone(), standalone); + assertEquals(startDocumentEvent.standaloneSet(), standaloneSet); + } }