You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/03/11 11:16:29 UTC
svn commit: r1299344 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/
axiom-tests/src/test/java/org/apache/axiom/om/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-test...
Author: veithen
Date: Sun Mar 11 10:16:29 2012
New Revision: 1299344
URL: http://svn.apache.org/viewvc?rev=1299344&view=rev
Log:
Fix for AXIOM-391.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConcurrentModification.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMChildElementIterator.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMChildElementIterator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMChildElementIterator.java?rev=1299344&r1=1299343&r2=1299344&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMChildElementIterator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMChildElementIterator.java Sun Mar 11 10:16:29 2012
@@ -20,93 +20,21 @@
package org.apache.axiom.om.impl.common;
import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
+import org.apache.axiom.om.impl.traverse.OMFilterIterator;
-import java.util.Iterator;
-
-public class OMChildElementIterator implements Iterator {
-
- /** Field currentChild */
- protected OMNode currentChild;
-
- /** Field lastChild */
- protected OMNode lastChild;
-
- /** Field nextCalled */
- protected boolean nextCalled = false;
-
- /** Field removeCalled */
- protected boolean removeCalled = false;
-
+public class OMChildElementIterator extends OMFilterIterator {
/**
* Constructor OMChildrenIterator.
*
* @param currentChild
*/
public OMChildElementIterator(OMElement currentChild) {
- this.currentChild = currentChild;
- }
-
- /**
- * Removes the last element returned by the iterator (optional operation) from the underlying
- * collection. This method can be called only once per call to <tt>next</tt>. The behavior of
- * an iterator is unspecified if the underlying collection is modified while the iteration is in
- * progress in any way other than by calling this method.
- *
- * @throws UnsupportedOperationException if the <tt>remove</tt> operation is not supported by
- * this Iterator.
- * @throws IllegalStateException if the <tt>next</tt> method has not yet been called, or
- * the <tt>remove</tt> method has already been called
- * after the last call to the <tt>next</tt> method.
- */
- public void remove() {
- if (!nextCalled) {
- throw new IllegalStateException(
- "next method has not yet being called");
- }
- if (removeCalled) {
- throw new IllegalStateException("remove has already being called");
- }
- removeCalled = true;
-
- // since this acts on the last child there is no need to mess with the current child
- if (lastChild == null) {
- throw new OMException("cannot remove a child at this stage!");
- }
- lastChild.detach();
+ super(new OMChildrenIterator(currentChild));
}
- /**
- * Returns <tt>true</tt> if the iteration has more elements. (In other words, returns
- * <tt>true</tt> if <tt>next</tt> would return an element rather than throwing an exception.)
- *
- * @return Returns <tt>true</tt> if the iterator has more elements.
- */
- public boolean hasNext() {
- return (currentChild != null);
- }
-
- /**
- * Returns the next element in the iteration.
- *
- * @return Returns the next element in the iteration.
- * @throws java.util.NoSuchElementException
- * iteration has no more elements.
- */
- public Object next() {
- nextCalled = true;
- removeCalled = false;
-
- if (hasNext()) {
- lastChild = currentChild;
- do {
- currentChild = currentChild.getNextOMSibling();
- } while (currentChild != null && currentChild.getType() != OMNode.ELEMENT_NODE);
-
-
- return lastChild;
- }
- return null;
+ protected boolean matches(OMNode node) {
+ return node instanceof OMElement;
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java?rev=1299344&r1=1299343&r2=1299344&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java Sun Mar 11 10:16:29 2012
@@ -146,8 +146,8 @@ public class StaxParserTest extends Abst
try {
while (childElements.hasNext()) {
childElements.next();
- fail("The stream should've been consumed by now!");
}
+ fail("The stream should've been consumed by now!");
} catch (Exception e) {
//if we are here without failing, then we are successful
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1299344&r1=1299343&r2=1299344&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Sun Mar 11 10:16:29 2012
@@ -146,6 +146,7 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.element.TestGetAttributeWithXmlPrefix1(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetAttributeWithXmlPrefix2(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetChildElements(metaFactory));
+ addTest(new org.apache.axiom.ts.om.element.TestGetChildElementsConcurrentModification(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetChildren(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetChildrenConcurrentModification(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetChildrenRemove1(metaFactory));
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConcurrentModification.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConcurrentModification.java?rev=1299344&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConcurrentModification.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConcurrentModification.java Sun Mar 11 10:16:29 2012
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.axiom.ts.om.element;
+
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that the iterator returned by {@link OMElement#getChildElements()} throws a
+ * {@link ConcurrentModificationException} if the current node is removed using a method other than
+ * {@link Iterator#remove()}. This is a regression test for
+ * <a href="https://issues.apache.org/jira/browse/AXIOM-391">AXIOM-391</a>.
+ */
+public class TestGetChildElementsConcurrentModification extends AxiomTestCase {
+ public TestGetChildElementsConcurrentModification(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMElement parent = factory.createOMElement("parent", null);
+ factory.createOMElement("child1", null, parent);
+ factory.createOMElement("child2", null, parent);
+ factory.createOMElement("child3", null, parent);
+ Iterator it = parent.getChildElements();
+ it.next();
+ OMElement child2 = (OMElement)it.next();
+ child2.detach();
+ try {
+ it.next();
+ fail("Expected ConcurrentModificationException");
+ } catch (ConcurrentModificationException ex) {
+ // Expected
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConcurrentModification.java
------------------------------------------------------------------------------
svn:eol-style = native