Skip to content

Commit c47ab5f

Browse files
MariusVolkhartJoeWang-Java
authored andcommitted
8256515: javax.xml.XMLEventReader produces incorrect START_DOCUMENT event
Reviewed-by: joehw
1 parent 291ba97 commit c47ab5f

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/java.xml/share/classes/com/sun/xml/internal/stream/events/StartDocumentEvent.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -102,9 +102,9 @@ public String getVersion() {
102102
return fVersion;
103103
}
104104

105-
public void setStandalone(boolean flag) {
106-
fStandaloneSet = true;
107-
fStandalone = flag;
105+
public void setStandalone(boolean isStandalone, boolean standaloneSet) {
106+
fStandaloneSet = standaloneSet;
107+
fStandalone = isStandalone;
108108
}
109109

110110
public void setStandalone(String s) {

src/java.xml/share/classes/com/sun/xml/internal/stream/events/XMLEventAllocatorImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -131,7 +131,7 @@ XMLEvent getXMLEvent(XMLStreamReader streamReader) {
131131
} else {
132132
sdEvent.setDeclaredEncoding(false);
133133
}
134-
sdEvent.setStandalone(streamReader.isStandalone());
134+
sdEvent.setStandalone(streamReader.isStandalone(), streamReader.standaloneSet());
135135
sdEvent.setLocation(streamReader.getLocation());
136136
event = sdEvent;
137137
break;

test/jaxp/javax/xml/jaxp/unittest/stream/XMLEventReaderTest/EventReaderTest.java

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,12 +28,18 @@
2828
import javax.xml.stream.XMLEventReader;
2929

3030
import javax.xml.stream.XMLInputFactory;
31+
import javax.xml.stream.XMLStreamException;
32+
import javax.xml.stream.events.StartDocument;
33+
34+
import org.testng.annotations.DataProvider;
3135
import org.testng.annotations.Listeners;
3236
import org.testng.annotations.Test;
3337

38+
import static org.testng.Assert.assertEquals;
39+
3440
/*
3541
* @test
36-
* @bug 8204329
42+
* @bug 8204329 8256515
3743
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
3844
* @run testng stream.XMLEventReaderTest.EventReaderTest
3945
* @summary Tests XMLEventReader
@@ -51,4 +57,23 @@ public void testNextEvent() throws Exception {
5157
// no more event
5258
eventReader.nextEvent();
5359
}
60+
61+
@DataProvider
62+
Object[][] standaloneSetTestData() {
63+
return new Object[][]{
64+
{"<?xml version=\"1.0\"?>", false, false},
65+
{"<?xml version=\"1.0\" standalone=\"no\"?>", false, true},
66+
{"<?xml version=\"1.0\" standalone=\"yes\"?>", true, true}
67+
};
68+
}
69+
70+
@Test(dataProvider = "standaloneSetTestData")
71+
void testStandaloneSet(String xml, boolean standalone, boolean standaloneSet) throws XMLStreamException {
72+
XMLInputFactory factory = XMLInputFactory.newInstance();
73+
XMLEventReader reader = factory.createXMLEventReader(new StringReader(xml));
74+
StartDocument startDocumentEvent = (StartDocument) reader.nextEvent();
75+
76+
assertEquals(startDocumentEvent.isStandalone(), standalone);
77+
assertEquals(startDocumentEvent.standaloneSet(), standaloneSet);
78+
}
5479
}

0 commit comments

Comments
 (0)