cvs commit: jakarta-bcel/src/java/org/apache/bcel/verifier/statics Pass3aVerifier.java

[email protected]
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
enver       02/04/26 15:35:41

  Modified:    src/java/org/apache/bcel/verifier/statics
                        Pass3aVerifier.java
  Log:
  Add checks for missing or wrongly-typed referenced fields.
  
  Revision  Changes    Path
  1.2       +32 -2     jakarta-bcel/src/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
  
  Index: Pass3aVerifier.java
  ===================================================================
  RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Pass3aVerifier.java	29 Oct 2001 20:00:37 -0000	1.1
  +++ Pass3aVerifier.java	26 Apr 2002 22:35:40 -0000	1.2
  @@ -69,7 +69,7 @@
    * More detailed information is to be found at the do_verify()
    * method's documentation. 
    *
  - * @version $Id: Pass3aVerifier.java,v 1.1 2001/10/29 20:00:37 jvanzyl Exp $
  + * @version $Id: Pass3aVerifier.java,v 1.2 2002/04/26 22:35:40 enver Exp $
    * @author <A HREF="http://www.inf.fu-berlin.de/~ehaase"/>Enver Haase</A>
    * @see #do_verify()
    */
  @@ -290,7 +290,7 @@
   		// The last byte of the last instruction in the code array must be the byte at index
   		// code_length-1 : See the do_verify() comments. We actually don't iterate through the
   		// byte array, but use an InstructionList so we cannot check for this. But BCEL does
  -		// things right, so it's implicitely okay.
  +		// things right, so it's implicitly okay.
   		
   		// TODO: Check how BCEL handles (and will handle) instructions like IMPDEP1, IMPDEP2,
   		//       BREAKPOINT... that BCEL knows about but which are illegal anyway.
  @@ -482,6 +482,36 @@
   			Constant c = cpg.getConstant(o.getIndex());
   			if (! (c instanceof ConstantFieldref)){
   				constraintViolated(o, "Indexing a constant that's not a CONSTANT_Fieldref but a '"+c+"'.");
  +			}
  +			
  +			String field_name = o.getFieldName(cpg);
  + 
  +			JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
  +			Field[] fields = jc.getFields();
  +			Field f = null;
  +			for (int i=0; i<fields.length; i++){
  +				if (fields[i].getName().equals(field_name)){
  +					f = fields[i];
  +					break;
  +				}
  +			}
  +			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()+"'.");
  +			}
  +			else{
  +				/* TODO: Check if assignment compatibility is sufficient.
  +				   What does Sun do? */
  +				Type f_type = Type.getType(f.getSignature());
  +				Type o_type = o.getType(cpg);
  +				
  +				/* TODO: Is there a way to make BCEL tell us if a field
  +				has a void method's signature, i.e. "()I" instead of "I"? */
  +				
  +				if (! f_type.equals(o_type)){
  +					constraintViolated(o, "Referenced field '"+field_name+"' has type '"+f_type+"' instead of '"+o_type+"' as expected.");
  +				}
  +				/* TODO: Check for access modifiers here. */
   			}
   		}
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.