commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Brosius <dbros...@apache.org>
Subject BCEL: Code Review Please
Date Fri, 22 Jul 2011 04:54:49 GMT
Found an collection type error when adding generics in this code below.

Collection was holding both ElementValueGen and ElementValue objects 
which are unrelated by inheritance.

Modified code so only ElementValueGen are in the collection, using

-			evalues.add(datums[i]);
+			evalues.add(ElementValueGen.copy(datums[i], cpool, true));



Do you folks agree this is the correct change?

-------- Original Message --------
Subject: 	svn commit: r1149461 - 
/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java 

Date: 	Fri, 22 Jul 2011 04:41:57 -0000
From: 	dbrosius@apache.org
Reply-To: 	dev@jakarta.apache.org
To: 	notifications@jakarta.apache.org



Author: dbrosius
Date: Fri Jul 22 04:41:56 2011
New Revision: 1149461

URL: http://svn.apache.org/viewvc?rev=1149461&view=rev
Log:
fix bad collection element type (ElementValueGen vs ElementValue) exposed by adding generics

Modified:
     jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java

Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java?rev=1149461&r1=1149460&r2=1149461&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java (original)
+++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java Fri
Jul 22 04:41:56 2011
@@ -22,6 +22,7 @@ import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
+
  import org.apache.bcel.classfile.ArrayElementValue;
  import org.apache.bcel.classfile.ElementValue;

@@ -29,12 +30,12 @@ public class ArrayElementValueGen extend
  {
  	// J5TODO: Should we make this an array or a list? A list would be easier to
  	// modify ...
-	private List /* ElementValueGen */evalues;
+	private List<ElementValueGen>  evalues;

  	public ArrayElementValueGen(ConstantPoolGen cp)
  	{
  		super(ARRAY, cp);
-		evalues = new ArrayList();
+		evalues = new ArrayList<ElementValueGen>();
  	}

  	public ArrayElementValueGen(int type, ElementValue[] datums,
@@ -44,10 +45,10 @@ public class ArrayElementValueGen extend
  		if (type != ARRAY)
  			throw new RuntimeException(
  					"Only element values of type array can be built with this ctor - type specified: "
+ type);
-		this.evalues = new ArrayList();
+		this.evalues = new ArrayList<ElementValueGen>();
  		for (int i = 0; i<  datums.length; i++)
  		{
-			evalues.add(datums[i]);
+			evalues.add(ElementValueGen.copy(datums[i], cpool, true));
  		}
  	}

@@ -58,9 +59,9 @@ public class ArrayElementValueGen extend
  	{
  		ElementValue[] immutableData = new ElementValue[evalues.size()];
  		int i = 0;
-		for (Iterator iter = evalues.iterator(); iter.hasNext();)
+		for (Iterator<ElementValueGen>  iter = evalues.iterator(); iter.hasNext();)
  		{
-			ElementValueGen element = (ElementValueGen) iter.next();
+			ElementValueGen element = iter.next();
  			immutableData[i++] = element.getElementValue();
  		}
  		return new ArrayElementValue(type, immutableData, cpGen
@@ -75,7 +76,7 @@ public class ArrayElementValueGen extend
  			boolean copyPoolEntries)
  	{
  		super(ARRAY, cpool);
-		evalues = new ArrayList();
+		evalues = new ArrayList<ElementValueGen>();
  		ElementValue[] in = value.getElementValuesArray();
  		for (int i = 0; i<  in.length; i++)
  		{
@@ -87,9 +88,9 @@ public class ArrayElementValueGen extend
  	{
  		dos.writeByte(type); // u1 type of value (ARRAY == '[')
  		dos.writeShort(evalues.size());
-		for (Iterator iter = evalues.iterator(); iter.hasNext();)
+		for (Iterator<ElementValueGen>  iter = evalues.iterator(); iter.hasNext();)
  		{
-			ElementValueGen element = (ElementValueGen) iter.next();
+			ElementValueGen element = iter.next();
  			element.dump(dos);
  		}
  	}
@@ -98,9 +99,9 @@ public class ArrayElementValueGen extend
  	{
  		StringBuffer sb = new StringBuffer();
  		sb.append("[");
-		for (Iterator iter = evalues.iterator(); iter.hasNext();)
+		for (Iterator<ElementValueGen>  iter = evalues.iterator(); iter.hasNext();)
  		{
-			ElementValueGen element = (ElementValueGen) iter.next();
+			ElementValueGen element = iter.next();
  			sb.append(element.stringifyValue());
  			if (iter.hasNext())
  				sb.append(",");
@@ -109,7 +110,7 @@ public class ArrayElementValueGen extend
  		return sb.toString();
  	}

-	public List getElementValues()
+	public List<ElementValueGen>  getElementValues()
  	{
  		return evalues;
  	}



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org




Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message