public static XField createXField(FieldAnnotation f) { return createXField(f.getClassName(), f.getFieldName(), f.getFieldSignature(), f.isStatic()); }
@Override public boolean match(BugInstance bugInstance) { FieldAnnotation fieldAnnotation = null; if (role == null || "".equals(role)) { fieldAnnotation = bugInstance.getPrimaryField(); } else { for (BugAnnotation a : bugInstance.getAnnotations()) { if (a instanceof FieldAnnotation && role.equals(a.getDescription())) { fieldAnnotation = (FieldAnnotation) a; break; } } } if (fieldAnnotation == null) { return false; } if (!name.match(fieldAnnotation.getFieldName())) { return false; } if (signature != null && !signature.match(fieldAnnotation.getFieldSignature())) { return false; } return true; }
public FieldDescriptor getFieldDescriptor(FieldAnnotation ma) { return getFieldDescriptor(ClassName.toSlashedClassName(ma.getClassName()), ma.getFieldName(), ma.getFieldSignature(), ma.isStatic()); }
return false; criteriaMatches &= fieldAnn.getFieldName().equals(fieldName);
static FieldAnnotation obfuscate(FieldAnnotation m) { FieldAnnotation result = new FieldAnnotation(hashClass(m.getClassName()), hashData(m.getFieldName()), hashSignature(m.getFieldSignature()), m.isStatic()); result.setDescription(m.getDescription()); return result; }
/** * Rewrite a FieldAnnotation to update the class name and field signature, * if needed. * * @param classNameRewriter * a ClassNameRewriter * @param annotation * a FieldAnnotation * @return the possibly-rewritten FieldAnnotation */ public static FieldAnnotation convertFieldAnnotation(ClassNameRewriter classNameRewriter, FieldAnnotation annotation) { if (classNameRewriter != IdentityClassNameRewriter.instance()) { annotation = new FieldAnnotation(classNameRewriter.rewriteClassName(annotation.getClassName()), annotation.getFieldName(), rewriteSignature(classNameRewriter, annotation.getFieldSignature()), annotation.isStatic()); } return annotation; }
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { XMLAttributeList attributeList = new XMLAttributeList().addAttribute("classname", getClassName()) .addAttribute("name", getFieldName()).addAttribute("signature", getFieldSignature()); if (fieldSourceSig != null) { attributeList.addAttribute("sourceSignature", fieldSourceSig); } attributeList.addAttribute("isStatic", String.valueOf(isStatic())); if (isPrimary) { attributeList.addAttribute("primary", "true"); } String role = getDescription(); if (!DEFAULT_ROLE.equals(role)) { attributeList.addAttribute("role", role); } xmlOutput.openTag(ELEMENT_NAME, attributeList); getSourceLines().writeXML(xmlOutput, addMessages, false); if (addMessages) { xmlOutput.openTag(BugAnnotation.MESSAGE_TAG); xmlOutput.writeText(this.toString()); xmlOutput.closeTag(BugAnnotation.MESSAGE_TAG); } xmlOutput.closeTag(ELEMENT_NAME); } }
if ("separator".equals(field.getFieldName()) && "java.io.File".equals(field.getClassName())) { i.setSpecialKind(Item.FILE_SEPARATOR_STRING);
public static XField createXField(FieldAnnotation f) { return createXField(f.getClassName(), f.getFieldName(), f.getFieldSignature(), f.isStatic()); }
public FieldDescriptor getFieldDescriptor(FieldAnnotation ma) { return getFieldDescriptor(ClassName.toSlashedClassName(ma.getClassName()), ma.getFieldName(), ma.getFieldSignature(), ma.isStatic()); }
@Override public boolean match(BugInstance bugInstance) { FieldAnnotation fieldAnnotation = null; if (role == null || "".equals(role)) { fieldAnnotation = bugInstance.getPrimaryField(); } else { for (BugAnnotation a : bugInstance.getAnnotations()) { if (a instanceof FieldAnnotation && role.equals(a.getDescription())) { fieldAnnotation = (FieldAnnotation) a; break; } } } if (fieldAnnotation == null) { return false; } if (!name.match(fieldAnnotation.getFieldName())) { return false; } if (signature != null && !signature.match(fieldAnnotation.getFieldSignature())) { return false; } return true; }
/** * implements the visitor to find collection fields * * @param obj * the context object of the currently parse field */ @Override public void visitField(Field obj) { if (obj.isPrivate()) { String signature = obj.getSignature(); if (signature.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX)) { try { JavaClass cls = Repository.lookupClass(SignatureUtils.stripSignature(signature)); if (cls.implementationOf(collectionClass) || cls.implementationOf(mapClass)) { FieldAnnotation fa = FieldAnnotation.fromVisitedField(this); collectionFields.put(fa.getFieldName(), new FieldInfo(fa)); } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } } } }
return false; criteriaMatches &= fieldAnn.getFieldName().equals(fieldName);
/** * implements the visitor to find collection fields * * @param obj * the context object of the currently parse field */ @Override public void visitField(Field obj) { if (obj.isPrivate()) { String signature = obj.getSignature(); if (signature.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX)) { try { JavaClass cls = Repository.lookupClass(SignatureUtils.stripSignature(signature)); if (cls.implementationOf(collectionClass) || cls.implementationOf(mapClass)) { FieldAnnotation fa = FieldAnnotation.fromVisitedField(this); collectionFields.put(fa.getFieldName(), new FieldInfo(fa)); } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } } } }
/** * Rewrite a FieldAnnotation to update the class name and field signature, * if needed. * * @param classNameRewriter * a ClassNameRewriter * @param annotation * a FieldAnnotation * @return the possibly-rewritten FieldAnnotation */ public static FieldAnnotation convertFieldAnnotation(ClassNameRewriter classNameRewriter, FieldAnnotation annotation) { if (classNameRewriter != IdentityClassNameRewriter.instance()) { annotation = new FieldAnnotation(classNameRewriter.rewriteClassName(annotation.getClassName()), annotation.getFieldName(), rewriteSignature(classNameRewriter, annotation.getFieldSignature()), annotation.isStatic()); } return annotation; }
static FieldAnnotation obfuscate(FieldAnnotation m) { FieldAnnotation result = new FieldAnnotation(hashClass(m.getClassName()), hashData(m.getFieldName()), hashSignature(m.getFieldSignature()), m.isStatic()); result.setDescription(m.getDescription()); return result; }
@Override public void doReportBug(BugInstance bugInstance) { if(includeCategories.size() > 0 && !includeCategories.contains(bugInstance.getCategoryAbbrev())) { return; } StringBuilder bugDetail = new StringBuilder(); bugDetail .append("\n------------------------------------------------------") .append("\nNew Bug Instance: [" + ++bugInstanceCount + "]") .append("\n message=" + bugInstance.getMessage()) .append("\n bugType=" + bugInstance.getBugPattern().getType()) .append(" priority=" + bugInstance.getPriorityString()) .append(" category=" + bugInstance.getCategoryAbbrev()); if (bugInstance.getPrimaryClass() != null) { bugDetail.append("\n class=" + bugInstance.getPrimaryClass().getClassName()); } if (bugInstance.getPrimaryMethod() != null) { bugDetail.append(" method=" + bugInstance.getPrimaryMethod().getMethodName()); } if (bugInstance.getPrimaryField() != null) { bugDetail.append(" field=" + bugInstance.getPrimaryField().getFieldName()); } if (bugInstance.getPrimarySourceLineAnnotation() != null) { bugDetail.append(" line=" + bugInstance.getPrimarySourceLineAnnotation().getStartLine()); } bugDetail.append("\n------------------------------------------------------"); log.info(bugDetail.toString()); //bugCollection.add(bugInstance); }
FieldAnnotation fieldAnn = extractBugAnnotation(bugInstance, FieldAnnotation.class); if (fieldAnn == null) return false; criteriaMatches &= fieldAnn.getFieldName().equals(fieldName);
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { XMLAttributeList attributeList = new XMLAttributeList().addAttribute("classname", getClassName()) .addAttribute("name", getFieldName()).addAttribute("signature", getFieldSignature()); if (fieldSourceSig != null) { attributeList.addAttribute("sourceSignature", fieldSourceSig); } attributeList.addAttribute("isStatic", String.valueOf(isStatic())); if (isPrimary) { attributeList.addAttribute("primary", "true"); } String role = getDescription(); if (!DEFAULT_ROLE.equals(role)) { attributeList.addAttribute("role", role); } xmlOutput.openTag(ELEMENT_NAME, attributeList); getSourceLines().writeXML(xmlOutput, addMessages, false); if (addMessages) { xmlOutput.openTag(BugAnnotation.MESSAGE_TAG); xmlOutput.writeText(this.toString()); xmlOutput.closeTag(BugAnnotation.MESSAGE_TAG); } xmlOutput.closeTag(ELEMENT_NAME); } }
if ("separator".equals(field.getFieldName()) && "java.io.File".equals(field.getClassName())) { i.setSpecialKind(Item.FILE_SEPARATOR_STRING);