From: Elliott Hughes Date: Thu, 24 Sep 2009 00:01:24 +0000 (-0700) Subject: Fix Node.getNextSibling bounds checking. X-Git-Tag: android-x86-2.2~634^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=5894bfbbbee7f9cd5b3b33e628c7d0291e2ece79;p=android-x86%2Fdalvik.git Fix Node.getNextSibling bounds checking. Obvious copy & paste error in InnerNodeImpl compared to LeafNodeImpl, plus new test. I've also fixed a typo that annoys me whenever I look at the XML test results, and removed a KnownFailure for a test that passes (and has been passing for some time). Bug: 779 --- diff --git a/libcore/xml/src/main/java/org/apache/harmony/xml/dom/InnerNodeImpl.java b/libcore/xml/src/main/java/org/apache/harmony/xml/dom/InnerNodeImpl.java index f71d289d2..2fd16d013 100644 --- a/libcore/xml/src/main/java/org/apache/harmony/xml/dom/InnerNodeImpl.java +++ b/libcore/xml/src/main/java/org/apache/harmony/xml/dom/InnerNodeImpl.java @@ -69,7 +69,7 @@ public abstract class InnerNodeImpl extends LeafNodeImpl { } public Node getNextSibling() { - if (parent == null || index >= parent.children.size()) { + if (parent == null || index + 1 >= parent.children.size()) { return null; } diff --git a/libcore/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java b/libcore/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java index c515d2057..292c2f1a7 100644 --- a/libcore/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java +++ b/libcore/xml/src/test/java/tests/api/javax/xml/parsers/DocumentBuilderTest.java @@ -278,7 +278,6 @@ public class DocumentBuilderTest extends TestCase { method = "parse", args = {java.io.File.class} ) - @KnownFailure("d.getChildNodes returns an unexpected/strange #Text node") public void test_parseLjava_io_File() throws IOException { File f = resourceToTmpFile("/simple.xml"); diff --git a/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTestSupport.java b/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTestSupport.java index bc5e6a149..a1627ba2c 100644 --- a/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTestSupport.java +++ b/libcore/xml/src/test/java/tests/api/javax/xml/parsers/SAXParserTestSupport.java @@ -54,7 +54,7 @@ class SAXParserTestSupport { public static final String KEY_ERROR = "error"; public static final String KEY_FATAL_ERROR = "fatalError"; public static final String KEY_WARNING = "warning"; - public static final String KEY_END_ELEMENT = "endEement"; + public static final String KEY_END_ELEMENT = "endElement"; public static final String KEY_END_PREFIX_MAPPING = "endPrefixMapping"; public static final String KEY_IGNORABLE_WHITE_SPACE = "ignorableWhitespace"; diff --git a/libcore/xml/src/test/java/tests/xml/AllTests.java b/libcore/xml/src/test/java/tests/xml/AllTests.java index eefae501f..8c089e311 100644 --- a/libcore/xml/src/test/java/tests/xml/AllTests.java +++ b/libcore/xml/src/test/java/tests/xml/AllTests.java @@ -26,6 +26,7 @@ public class AllTests { suite.addTestSuite(SimpleParserTest.class); suite.addTestSuite(SimpleBuilderTest.class); + suite.addTestSuite(NodeTests.class); //suite.addTest(tests.org.w3c.dom.AllTests.suite()); suite.addTest(tests.api.javax.xml.parsers.AllTests.suite()); diff --git a/libcore/xml/src/test/java/tests/xml/NodeTests.java b/libcore/xml/src/test/java/tests/xml/NodeTests.java new file mode 100644 index 000000000..e46e216d5 --- /dev/null +++ b/libcore/xml/src/test/java/tests/xml/NodeTests.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.xml; + +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetNew; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import java.io.ByteArrayInputStream; +import javax.xml.parsers.DocumentBuilderFactory; + +@TestTargetClass(Node.class) +public class NodeTests extends TestCase { + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Issue #779: org.w3c.dom.Node#getNextSibling throws IndexOutOfBoundsException.", + method = "getNextSibling", + args = {} + ) + public void test_getNextSibling() throws Exception { + // Calling getNextSibling when there is no next sibling should return null. + // From http://code.google.com/p/android/issues/detail?id=779. + ByteArrayInputStream bis = new ByteArrayInputStream("".getBytes()); + Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bis); + Node root = document.getDocumentElement(); + assertNull(root.getNextSibling()); + } +}