void newFileMenuItem_actionPerformed( final ActionEvent e ) { final String classname = JOptionPane .showInputDialog("Please enter the fully qualified name of a class or interface to verify:"); if ((classname == null) || (classname.isEmpty())) { return; } VerifierFactory.getVerifier(classname); // let observers do the rest. classNamesJList.setSelectedValue(classname, true); }
void newFileMenuItem_actionPerformed(ActionEvent e) { String classname = JOptionPane.showInputDialog("Please enter the fully qualified name of a class or interface to verify:"); if ((classname == null) || (classname.equals(""))) return; VerifierFactory.getVerifier(classname); // let observers do the rest. classNamesJList.setSelectedValue(classname, true); }
/** * This method implements a demonstration program * of how to use the VerifierFactoryObserver. It transitively verifies * all class files encountered; this may take up a lot of time and, * more notably, memory. */ public static void main(String[] args){ if (args.length != 1){ System.out.println("Need exactly one argument: The root class to verify."); System.exit(1); } int dotclasspos = args[0].lastIndexOf(".class"); if (dotclasspos != -1) args[0] = args[0].substring(0,dotclasspos); args[0] = args[0].replace('/', '.'); TransitiveHull th = new TransitiveHull(); VerifierFactory.attach(th); VerifierFactory.getVerifier(args[0]); // the observer is called back and does the actual trick. VerifierFactory.detach(th); } }
/** * This method implements a demonstration program * of how to use the VerifierFactoryObserver. It transitively verifies * all class files encountered; this may take up a lot of time and, * more notably, memory. */ public static void main( final String[] args ) { if (args.length != 1) { System.out.println("Need exactly one argument: The root class to verify."); System.exit(1); } final int dotclasspos = args[0].lastIndexOf(".class"); if (dotclasspos != -1) { args[0] = args[0].substring(0, dotclasspos); } args[0] = args[0].replace('/', '.'); final TransitiveHull th = new TransitiveHull(); VerifierFactory.attach(th); VerifierFactory.getVerifier(args[0]); // the observer is called back and does the actual trick. VerifierFactory.detach(th); } }
/** Machine-generated. */ public void flushButton_ActionPerformed( final java.awt.event.ActionEvent actionEvent ) { VerifierFactory.getVerifier(class_name).flush(); Repository.removeClass(class_name); // Make sure it will be reloaded. getPass1Panel().setBackground(Color.gray); getPass1Panel().repaint(); getPass2Panel().setBackground(Color.gray); getPass2Panel().repaint(); getPass3Panel().setBackground(Color.gray); getPass3Panel().repaint(); }
/** Machine-generated. */ public void flushButton_ActionPerformed(java.awt.event.ActionEvent actionEvent) { VerifierFactory.getVerifier(class_name).flush(); Repository.removeClass(class_name); // Make sure it will be reloaded. getPass1Panel().setBackground(Color.gray); getPass1Panel().repaint(); getPass2Panel().setBackground(Color.gray); getPass2Panel().repaint(); getPass3Panel().setBackground(Color.gray); getPass3Panel().repaint(); }
/** Machine-generated. */ public void pass1Button_ActionPerformed( final java.awt.event.ActionEvent actionEvent ) { final Verifier v = VerifierFactory.getVerifier(class_name); final VerificationResult vr = v.doPass1(); if (vr.getStatus() == VerificationResult.VERIFIED_OK) { getPass1Panel().setBackground(Color.green); getPass1Panel().repaint(); } if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) { getPass1Panel().setBackground(Color.red); getPass1Panel().repaint(); } }
/** Machine-generated. */ public void pass1Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) { Verifier v = VerifierFactory.getVerifier(class_name); VerificationResult vr = v.doPass1(); if (vr.getStatus() == VerificationResult.VERIFIED_OK){ getPass1Panel().setBackground(Color.green); getPass1Panel().repaint(); } if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ getPass1Panel().setBackground(Color.red); getPass1Panel().repaint(); } }
synchronized void pass3aJList_valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; Verifier v = VerifierFactory.getVerifier(current_class); String all3amsg = ""; boolean all3aok = true; boolean rejected = false; for (int i=0; i<pass3aJList.getModel().getSize(); i++){ if (pass3aJList.isSelectedIndex(i)){ VerificationResult vr = v.doPass3a(i); if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ all3aok = false; rejected = true; } all3amsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n"; } } pass3aTextPane.setText(all3amsg); pass3aTextPane.setBackground(all3aok? Color.green : (rejected? Color.red : Color.yellow)); }
synchronized void pass3bJList_valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; Verifier v = VerifierFactory.getVerifier(current_class); String all3bmsg = ""; boolean all3bok = true; boolean rejected = false; for (int i=0; i<pass3bJList.getModel().getSize(); i++){ if (pass3bJList.isSelectedIndex(i)){ VerificationResult vr = v.doPass3b(i); if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ all3bok = false; rejected = true; } all3bmsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n"; } } pass3bTextPane.setText(all3bmsg); pass3bTextPane.setBackground(all3bok? Color.green : (rejected? Color.red : Color.yellow)); }
/** Machine-generated. */ public void pass2Button_ActionPerformed( final java.awt.event.ActionEvent actionEvent ) { pass1Button_ActionPerformed(actionEvent); final Verifier v = VerifierFactory.getVerifier(class_name); final VerificationResult vr = v.doPass2(); if (vr.getStatus() == VerificationResult.VERIFIED_OK) { getPass2Panel().setBackground(Color.green); getPass2Panel().repaint(); } if (vr.getStatus() == VerificationResult.VERIFIED_NOTYET) { getPass2Panel().setBackground(Color.yellow); getPass2Panel().repaint(); } if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) { getPass2Panel().setBackground(Color.red); getPass2Panel().repaint(); } }
/** Machine-generated. */ public void pass2Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) { pass1Button_ActionPerformed(actionEvent); Verifier v = VerifierFactory.getVerifier(class_name); VerificationResult vr = v.doPass2(); if (vr.getStatus() == VerificationResult.VERIFIED_OK){ getPass2Panel().setBackground(Color.green); getPass2Panel().repaint(); } if (vr.getStatus() == VerificationResult.VERIFIED_NOTYET){ getPass2Panel().setBackground(Color.yellow); getPass2Panel().repaint(); } if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){ getPass2Panel().setBackground(Color.red); getPass2Panel().repaint(); } }
public void update(String classname){ System.gc(); // avoid swapping if possible. for (int i=0; i<indent; i++){ System.out.print(" "); } System.out.println(classname); indent += 1; Verifier v = VerifierFactory.getVerifier(classname); VerificationResult vr; vr = v.doPass1(); if (vr != VerificationResult.VR_OK) //System.exit(1); System.out.println("Pass 1:\n"+vr); vr = v.doPass2(); if (vr != VerificationResult.VR_OK) //System.exit(1); System.out.println("Pass 2:\n"+vr); if (vr == VerificationResult.VR_OK){ JavaClass jc = Repository.lookupClass(v.getClassName()); for (int i=0; i<jc.getMethods().length; i++){ vr = v.doPass3a(i); if (vr != VerificationResult.VR_OK) //System.exit(1); System.out.println(v.getClassName()+", Pass 3a, method "+i+" ['"+jc.getMethods()[i]+"']:\n"+vr); vr = v.doPass3b(i); if (vr != VerificationResult.VR_OK) //System.exit(1); System.out.println(v.getClassName()+", Pass 3b, method "+i+" ['"+jc.getMethods()[i]+"']:\n"+vr); } } indent -= 1; }
/** Machine-generated. */ public void pass4Button_ActionPerformed(java.awt.event.ActionEvent actionEvent) { pass2Button_ActionPerformed(actionEvent); Color color = Color.green; Verifier v = VerifierFactory.getVerifier(class_name); VerificationResult vr = v.doPass2(); if (vr.getStatus() == VerificationResult.VERIFIED_OK){ JavaClass jc = Repository.lookupClass(class_name); int nr = jc.getMethods().length; for (int i=0; i<nr; i++) { vr = v.doPass3b(i); if (vr.getStatus() != VerificationResult.VERIFIED_OK){ color = Color.red; break; } } } else{ color = Color.yellow; } getPass3Panel().setBackground(color); getPass3Panel().repaint(); } }
/** * Assures the generic preconditions of a LoadClass instance. * The referenced class is loaded and pass2-verified. */ public void visitLoadClass(LoadClass o){ ObjectType t = o.getLoadClassType(cpg); if (t != null){// null means "no class is loaded" Verifier v = VerifierFactory.getVerifier(t.getClassName()); VerificationResult vr = v.doPass2(); if (vr.getStatus() != VerificationResult.VERIFIED_OK){ constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); } } }
/** * Assures the generic preconditions of a LoadClass instance. * The referenced class is loaded and pass2-verified. */ public void visitLoadClass(LoadClass o){ ObjectType t = o.getLoadClassType(cpg); if (t != null){// null means "no class is loaded" Verifier v = VerifierFactory.getVerifier(t.getClassName()); VerificationResult vr = v.doPass1(); if (vr.getStatus() != VerificationResult.VERIFIED_OK){ constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded: '"+vr+"'."); } } }
/** * Assures the generic preconditions of a LoadClass instance. * The referenced class is loaded and pass2-verified. */ @Override public void visitLoadClass(final LoadClass o) { final ObjectType t = o.getLoadClassType(cpg); if (t != null) {// null means "no class is loaded" final Verifier v = VerifierFactory.getVerifier(t.getClassName()); final VerificationResult vr = v.doPass1(); if (vr.getStatus() != VerificationResult.VERIFIED_OK) { constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded: '"+vr+"'."); } } }
/** * Assures the generic preconditions of a LoadClass instance. * The referenced class is loaded and pass2-verified. */ @Override public void visitLoadClass(final LoadClass o) { final ObjectType t = o.getLoadClassType(cpg); if (t != null) {// null means "no class is loaded" final Verifier v = VerifierFactory.getVerifier(t.getClassName()); final VerificationResult vr = v.doPass2(); if (vr.getStatus() != VerificationResult.VERIFIED_OK) { constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+ "' is referenced, but cannot be loaded and resolved: '"+vr+"'."); } } }
/** * Ensures the general preconditions of a FieldInstruction instance. */ @Override public void visitFieldInstruction(final FieldInstruction o) { // visitLoadClass(o) has been called before: Every FieldOrMethod // implements LoadClass. // visitCPInstruction(o) has been called before. // A FieldInstruction may be: GETFIELD, GETSTATIC, PUTFIELD, PUTSTATIC final Constant c = cpg.getConstant(o.getIndex()); if (!(c instanceof ConstantFieldref)) { constraintViolated(o, "Index '"+o.getIndex()+"' should refer to a CONSTANT_Fieldref_info structure, but refers to '"+c+"'."); } // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o). final Type t = o.getType(cpg); if (t instanceof ObjectType) { final String name = ((ObjectType)t).getClassName(); final Verifier v = VerifierFactory.getVerifier( name ); final VerificationResult vr = v.doPass2(); if (vr.getStatus() != VerificationResult.VERIFIED_OK) { constraintViolated(o, "Class '"+name+"' is referenced, but cannot be loaded and resolved: '"+vr+"'."); } } }
public void testDefaultMethodValidation() { final String classname = Collection.class.getName(); final Verifier verifier = VerifierFactory.getVerifier(classname); VerificationResult result = verifier.doPass1(); assertEquals("Pass 1 verification of " + classname + " failed: " + result.getMessage(), VerificationResult.VERIFIED_OK, result.getStatus()); result = verifier.doPass2(); assertEquals("Pass 2 verification of " + classname + " failed: " + result.getMessage(), VerificationResult.VERIFIED_OK, result.getStatus()); } }