8256515: javax.xml.XMLEventReader produces incorrect START_DOCUMENT event

Reviewed-by: joehw
This commit is contained in:
Marius Volkhart 2020-12-08 20:43:42 +00:00 committed by Joe Wang
parent 291ba97fab
commit c47ab5f6b7
3 changed files with 33 additions and 8 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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[][]{
{"<?xml version=\"1.0\"?>", false, false},
{"<?xml version=\"1.0\" standalone=\"no\"?>", false, true},
{"<?xml version=\"1.0\" standalone=\"yes\"?>", 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);
}
}