You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by le...@apache.org on 2007/07/31 11:39:45 UTC
svn commit: r561285 - in /harmony/enhanced/classlib/trunk/modules/luni/src:
main/java/java/util/Stack.java
test/api/common/tests/api/java/util/StackTest.java
Author: leoli
Date: Tue Jul 31 02:39:44 2007
New Revision: 561285
URL: http://svn.apache.org/viewvc?view=rev&rev=561285
Log:
Apply patch for HARMONY-4577( [classlib][luni] Stack.pop method of harmony throws EmptyStackException, while RI throws ArrayIndexOutOfBoundsException).
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/StackTest.java
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java?view=diff&rev=561285&r1=561284&r2=561285
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java Tue Jul 31 02:39:44 2007
@@ -39,7 +39,7 @@
*
* @return true if the stack is empty, false otherwise
*/
- public boolean empty() {
+ public synchronized boolean empty() {
return elementCount == 0;
}
@@ -71,14 +71,14 @@
*/
@SuppressWarnings("unchecked")
public synchronized E pop() {
- try {
- int index = elementCount - 1;
- E obj = (E)elementData[index];
- removeElementAt(index);
- return obj;
- } catch (IndexOutOfBoundsException e) {
- throw new EmptyStackException();
- }
+ if(elementCount == 0){
+ throw new EmptyStackException();
+ }
+ final int index = --elementCount;
+ final E obj = (E)elementData[index];
+ elementData[index] = null;
+ modCount++;
+ return obj;
}
/**
@@ -92,7 +92,7 @@
* @see #peek
* @see #pop
*/
- public synchronized E push(E object) {
+ public E push(E object) {
addElement(object);
return object;
}
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/StackTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/StackTest.java?view=diff&rev=561285&r1=561284&r2=561285
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/StackTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/StackTest.java Tue Jul 31 02:39:44 2007
@@ -155,6 +155,45 @@
assertEquals("Search returned incorrect value for search for null--wanted -1",
-1, s.search(null));
}
+
+ static class BugStack<E> extends Stack<E>{
+ /**
+ *
+ */
+ private static final long serialVersionUID = -9133762075342926141L;
+
+ /**
+ *
+ */
+ public void setLength(int elementCount)
+ {
+ this.elementCount = elementCount;
+ }
+
+ public int getLength()
+ {
+ return elementCount;
+ }
+ }
+
+ //test for wrong exception threw by pop method
+ public void test_pop_modify_elementCount(){
+ BugStack<String> testStack = new BugStack<String>();
+ testStack.push("A");
+ testStack.push("B");
+ testStack.setLength(20);
+ try{
+ testStack.pop();
+ }
+ catch(ArrayIndexOutOfBoundsException e)
+ {
+ //Expected to throw ArrayIndexOutOfBoundsException here
+ }
+ catch(EmptyStackException e)
+ {
+ fail("Should throw ArrayIndexOutOfBoundsException here");
+ }
+ }
/**
* Sets up the fixture, for example, open a network connection. This method
Re: svn commit: r561285 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Stack.java test/api/common/tests/api/java/util/StackTest.java
Posted by Spark Shen <sm...@gmail.com>.
Yes, I think so.
2007/7/31, Leo Li <li...@gmail.com>:
>
> On 7/31/07, Tim Ellison <t....@gmail.com> wrote:
> >
> > leoli@apache.org wrote:
> > > Modified:
> >
> harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
> > > URL:
> >
> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java?view=diff&rev=561285&r1=561284&r2=561285
> > >
> >
> ==============================================================================
> > > ---
> >
> harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
> > (original)
> > > +++
> >
> harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
> > Tue Jul 31 02:39:44 2007
> > > @@ -39,7 +39,7 @@
> > > *
> > > * @return true if the stack is empty, false otherwise
> > > */
> > > - public boolean empty() {
> > > + public synchronized boolean empty() {
> > > return elementCount == 0;
> > > }
> >
> > Why make this synchronized?
>
>
> The synchronize on empty() method seems unnecessary.
> I have removed it at r561301. Is it all right, Spark?
>
> Regards,
> > Tim
> >
>
>
>
> --
> Leo Li
> China Software Development Lab, IBM
>
--
Spark Shen
China Software Development Lab, IBM
Re: svn commit: r561285 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Stack.java test/api/common/tests/api/java/util/StackTest.java
Posted by Leo Li <li...@gmail.com>.
On 7/31/07, Tim Ellison <t....@gmail.com> wrote:
>
> leoli@apache.org wrote:
> > Modified:
> harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
> > URL:
> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java?view=diff&rev=561285&r1=561284&r2=561285
> >
> ==============================================================================
> > ---
> harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
> (original)
> > +++
> harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
> Tue Jul 31 02:39:44 2007
> > @@ -39,7 +39,7 @@
> > *
> > * @return true if the stack is empty, false otherwise
> > */
> > - public boolean empty() {
> > + public synchronized boolean empty() {
> > return elementCount == 0;
> > }
>
> Why make this synchronized?
The synchronize on empty() method seems unnecessary.
I have removed it at r561301. Is it all right, Spark?
Regards,
> Tim
>
--
Leo Li
China Software Development Lab, IBM
Re: svn commit: r561285 - in /harmony/enhanced/classlib/trunk/modules/luni/src:
main/java/java/util/Stack.java test/api/common/tests/api/java/util/StackTest.java
Posted by Tim Ellison <t....@gmail.com>.
leoli@apache.org wrote:
> Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java
> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java?view=diff&rev=561285&r1=561284&r2=561285
> ==============================================================================
> --- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java (original)
> +++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Stack.java Tue Jul 31 02:39:44 2007
> @@ -39,7 +39,7 @@
> *
> * @return true if the stack is empty, false otherwise
> */
> - public boolean empty() {
> + public synchronized boolean empty() {
> return elementCount == 0;
> }
Why make this synchronized?
Regards,
Tim