svn commit: r226610 - in /jakarta/bcel/trunk/src/java/org/apache/bcel/verifier: statics/Pass3aVerifier.java structurals/InstConstraintVisitor.java

[email protected]
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
Author: dbrosius
Date: Sun Jul 31 00:07:38 2005
New Revision: 226610

URL: http://svn.apache.org/viewcvs?rev=226610&view=rev
Log:
Fix 27855: If a GETFIELD is called and the field is not found in the class, look for public or protected members with the same name in a super class.

Modified:
    jakarta/bcel/trunk/src/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
    jakarta/bcel/trunk/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java

Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java?rev=226610&r1=226609&r2=226610&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java Sun Jul 31 00:07:38 2005
@@ -562,8 +562,25 @@
 				}
 			}
 			if (f == null){
-				/* TODO: also look up if the field is inherited! */
-				constraintViolated(o, "Referenced field '"+field_name+"' does not exist in class '"+jc.getClassName()+"'.");
+				JavaClass[] superclasses = jc.getSuperClasses();
+				outer: 
+				for (int j=0; j<superclasses.length; j++){
+					fields = superclasses[j].getFields();
+					for (int i=0; i<fields.length; i++){
+						if (fields[i].getName().equals(field_name)){
+							Type f_type = Type.getType(fields[i].getSignature());
+							Type o_type = o.getType(cpg);
+							if (f_type.equals(o_type)){
+								f = fields[i];
+								if ((f.getAccessFlags() & (Constants.ACC_PUBLIC | Constants.ACC_PROTECTED)) == 0)
+									f = null;
+								break outer;
+							}
+						}
+					}
+				}
+				if (f == null)
+					constraintViolated(o, "Referenced field '"+field_name+"' does not exist in class '"+jc.getClassName()+"'.");
 			}
 			else{
 				/* TODO: Check if assignment compatibility is sufficient.

Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java?rev=226610&r1=226609&r2=226610&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java Sun Jul 31 00:07:38 2005
@@ -1173,8 +1173,27 @@
 					}
 			}
 		}
+
 		if (f == null){
-			throw new AssertionViolatedException("Field not found?!?");
+			JavaClass[] superclasses = jc.getSuperClasses();
+			outer: 
+			for (int j=0; j<superclasses.length; j++){
+				fields = superclasses[j].getFields();
+				for (int i=0; i<fields.length; i++){
+					if (fields[i].getName().equals(field_name)){
+						Type f_type = Type.getType(fields[i].getSignature());
+						Type o_type = o.getType(cpg);
+						if (f_type.equals(o_type)){
+							f = fields[i];
+							if ((f.getAccessFlags() & (Constants.ACC_PUBLIC | Constants.ACC_PROTECTED)) == 0)
+								f = null;
+							break outer;
+						}
+					}
+				}
+			}
+			if (f == null)
+				throw new AssertionViolatedException("Field '"+field_name+"' not found?!?");
 		}
 
 		if (f.isProtected()){
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.