/** * Remembers the class name and resets temporary fields. */ @Override public void visit(JavaClass someObj) { currentClass = someObj.getClassName(); currentMethod = null; currentCFG = null; currentLockDataFlow = null; sawDateClass = false; }
public ClassParserUsingBCEL(JavaClass javaClass, @CheckForNull ClassDescriptor expectedClassDescriptor, ICodeBaseEntry codeBaseEntry) { this.javaClass = javaClass; this.slashedClassName = javaClass.getClassName().replace('.', '/'); this.expectedClassDescriptor = expectedClassDescriptor; this.codeBaseEntry = codeBaseEntry; }
@Override public void removeClass(JavaClass javaClass) { nameToClassMap.remove(javaClass.getClassName()); if (DEBUG) { System.out.println("Removing class " + javaClass.getClassName() + " from Repository"); dumpStack(); } }
private static boolean isSuspiciousName(String fullFieldName, JavaClass obj) { int classNameLength = obj.getClassName().length(); // do not search pattern in class name (signature not important) String fieldName = fullFieldName.substring(classNameLength); return PASSWORD_PATTERN.matcher(fieldName).matches(); }
Scanner(JavaClass theClass, Method targetMethod, int targetPC) { if(DEBUG) { System.out.println("Scanning " + theClass.getClassName() + "." + targetMethod.getName()); } this.theClass = theClass; this.targetMethod = targetMethod; this.targetPC = targetPC; }
@Override public void visitClassContext(ClassContext classContext) { JavaClass cls = classContext.getJavaClass(); clsName = cls.getClassName(); if (clsName.indexOf('$') >= 0) { super.visitClassContext(classContext); } }
@Override public void visitJavaClass(JavaClass obj) { isInnerClass = false; // totally skip methods not defined in inner classes if (obj.getClassName().indexOf('$') >= 0) { super.visitJavaClass(obj); bugAccumulator.reportAccumulatedBugs(); } }
@Override public void visitClassContext(ClassContext classContext) { JavaClass cls = classContext.getJavaClass(); if ((!cls.isPublic()) || (cls.getClassName().indexOf('$') >= 0)) { return; } alreadyReported = false; super.visitClassContext(classContext); }
/** * Convenience method for generating a method signature in human readable * form. * * @param javaClass * the class * @param method * the method */ public static String convertMethodSignature(JavaClass javaClass, Method method) { return convertMethodSignature(javaClass.getClassName(), method.getName(), method.getSignature()); }
@Override public void visitJavaClass(JavaClass obj) { JCIPAnnotationDatabase jcipAnotationDatabase = AnalysisContext.currentAnalysisContext().getJCIPAnnotationDatabase(); if (jcipAnotationDatabase.hasClassAnnotation(obj.getClassName().replace('/', '.'), "Immutable")) { super.visitJavaClass(obj); } }
/** * Construct a ClassDescriptor from a JavaClass. * * @param jclass * a JavaClass * @return a ClassDescriptor identifying that JavaClass */ public static ClassDescriptor getClassDescriptor(JavaClass jclass) { return DescriptorFactory.instance().getClassDescriptor(ClassName.toSlashedClassName(jclass.getClassName())); }
/** * Factory method. Construct from class name and BCEL Field object. * * @param jClass * the class which defines the field * @param field * the BCEL Field object * @return the FieldAnnotation */ public static FieldAnnotation fromBCELField(JavaClass jClass, Field field) { return new FieldAnnotation(jClass.getClassName(), field.getName(), field.getSignature(), field.isStatic()); }
@Override public void observeClass(ClassDescriptor classDescriptor) { try { JavaClass javaClass = AnalysisContext.currentAnalysisContext().lookupClass(classDescriptor.toDottedClassName()); String sourceFileName = fileNameFor(javaClass.getPackageName(), javaClass.getSourceFileName()); sourceFileNameCache.put(javaClass.getClassName(), sourceFileName); } catch (ClassNotFoundException e) { // Ignore - should not happen } }
public static @DottedClassName String findSuperImplementor(@DottedClassName String clazz, String name, String signature, BugReporter bugReporter) { try { JavaClass c = findImplementor(Repository.getSuperClasses(clazz), name, signature); return (c != null) ? c.getClassName() : clazz; } catch (ClassNotFoundException e) { bugReporter.reportMissingClass(e); return clazz; } }
public static OpcodeStack getStackAt(JavaClass theClass, Method method, int pc) { Scanner scanner = new Scanner(theClass, method, pc); try { scanner.execute(); } catch (EarlyExitException e) { return e.stack; } throw new UnreachableCodeException(theClass.getClassName(), method.getName(), method.getSignature(), pc); }
public void dumpSimpleDataflowInformation(Method method) { try { dumpDataflowInformation(method, getCFG(method), getValueNumberDataflow(method), getIsNullValueDataflow(method), null, null); } catch (DataflowAnalysisException e) { AnalysisContext.logError( "Could not dump data information for " + getJavaClass().getClassName() + "." + method.getName(), e); } catch (CFGBuilderException e) { AnalysisContext.logError( "Could not dump data information for " + getJavaClass().getClassName() + "." + method.getName(), e); } }
public void dumpDataflowInformation(Method method) { try { dumpDataflowInformation(method, getCFG(method), getValueNumberDataflow(method), getIsNullValueDataflow(method), getUnconditionalValueDerefDataflow(method), getTypeDataflow(method)); } catch (DataflowAnalysisException e) { AnalysisContext.logError( "Could not dump data information for " + getJavaClass().getClassName() + "." + method.getName(), e); } catch (CFGBuilderException e) { AnalysisContext.logError( "Could not dump data information for " + getJavaClass().getClassName() + "." + method.getName(), e); } }
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { ClassGen cg = new ClassGen(name, Object.class.getName(), "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, new String[] {Serializable.class.getName()}); cg.addEmptyConstructor(Constants.ACC_PUBLIC); JavaClass jClazz = cg.getJavaClass(); byte[] bytes = jClazz.getBytes(); return defineClass(jClazz.getClassName(), bytes, 0, bytes.length); }
@Override public void visitField(Field obj) { if (obj.isProtected()) { bugReporter.reportBug(new BugInstance(this, "CI_CONFUSED_INHERITANCE", LOW_PRIORITY).addClass(cls).addField( new FieldAnnotation(cls.getClassName(), obj.getName(), obj.getSignature(), obj.isStatic()))); } }
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { ClassGen cg = new ClassGen(name, "java.lang.Object", "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null); cg.addEmptyConstructor(Constants.ACC_PUBLIC); JavaClass jClazz = cg.getJavaClass(); byte[] bytes = jClazz.getBytes(); return defineClass(jClazz.getClassName(), bytes, 0, bytes.length); }