static MethodAnnotation obfuscate(MethodAnnotation m) { String className = m.getClassName(); if (className.startsWith("java")) { return m; } String methodName = m.getMethodName(); String methodSignature = m.getMethodSignature(); if ("hashCode".equals(methodName) && "()I".equals(methodSignature) || "equals".equals(methodName) && "(Ljava/lang/Object;)Z".equals(methodSignature) || "compareTo".equals(methodName) && "(Ljava/lang/Object;)I".equals(methodSignature) || "<init>".equals(methodName) || "<clinit>".equals(methodName)) { // don't need to obfuscate method name } else { methodName = hashData(methodName); } MethodAnnotation result = new MethodAnnotation(hashClass(className), methodName, hashMethodSignature(methodSignature), m.isStatic()); result.setDescription(m.getDescription()); return result; }
if (!omitMethodName) { if (useJVMMethodName) { result.append(getMethodName()); } else { result.append(getJavaSourceMethodName());
public static XMethod createXMethod(MethodAnnotation ma) { return createXMethod(ma.getClassName(), ma.getMethodName(), ma.getMethodSignature(), ma.isStatic()); }
@Override public boolean match(BugInstance bugInstance) { MethodAnnotation methodAnnotation = null; if (role == null || "".equals(role)) { methodAnnotation = bugInstance.getPrimaryMethod(); } else { for (BugAnnotation a : bugInstance.getAnnotations()) { if (a instanceof MethodAnnotation && role.equals(a.getDescription())) { methodAnnotation = (MethodAnnotation) a; break; } } } if (methodAnnotation == null) { return false; } if (!name.match(methodAnnotation.getMethodName())) { return false; } if (signature != null && !signature.match(methodAnnotation.getMethodSignature())) { return false; } return true; }
public MethodDescriptor getMethodDescriptor(MethodAnnotation ma) { return getMethodDescriptor(ClassName.toSlashedClassName(ma.getClassName()), ma.getMethodName(), ma.getMethodSignature(), ma.isStatic()); }
if(methodAnn.getMethodName().startsWith("apply") && fullClassName != null) { Matcher m = ANON_FUNCTION_SCALA_PATTERN.matcher(fullClassName); if(m.find()) { //Scala function enclose in criteriaMatches &= methodAnn.getMethodName().equals(methodName) || methodName.equals(m.group(1)); criteriaMatches &= methodAnn.getMethodName().equals(methodName);
String methodName = m.getMethodName(); if (methodName.equals(simpleClassName) && "()V".equals(m.getMethodSignature())) { continue;
/** * Rewrite a MethodAnnotation to update the class name, and any class names * mentioned in the method signature. * * @param classNameRewriter * a ClassNameRewriter * @param annotation * a MethodAnnotation * @return the possibly-rewritten MethodAnnotation */ public static MethodAnnotation convertMethodAnnotation(ClassNameRewriter classNameRewriter, MethodAnnotation annotation) { if (classNameRewriter != IdentityClassNameRewriter.instance()) { annotation = new MethodAnnotation(classNameRewriter.rewriteClassName(annotation.getClassName()), annotation.getMethodName(), rewriteMethodSignature(classNameRewriter, annotation.getMethodSignature()), annotation.isStatic()); } return annotation; }
if (downCast && operandTypeIsExact) { if ("[Ljava/lang/Object;".equals(refSig) && source instanceof MethodAnnotation && "toArray".equals(((MethodAnnotation) source).getMethodName()) && "()[Ljava/lang/Object;".equals(((MethodAnnotation) source).getMethodSignature())) { bugPattern = "BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY"; && "toArray".equals(((MethodAnnotation) source).getMethodName()) && "()[Ljava/lang/Object;".equals(((MethodAnnotation) source).getMethodSignature())) { bugReporter.reportBug(new BugInstance(this, "BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY", HIGH_PRIORITY)
return false; if (!callsPattern.matcher(m.getClassName()).find() && !callsPattern.matcher(m.getMethodName()).find()) { return false;
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { XMLAttributeList attributeList = new XMLAttributeList().addAttribute("classname", getClassName()) .addAttribute("name", getMethodName()).addAttribute("signature", getMethodSignature()) .addAttribute("isStatic", String.valueOf(isStatic())); if (isPrimary) { attributeList.addAttribute("primary", "true"); } String role = getDescription(); if (!DEFAULT_ROLE.equals(role)) { attributeList.addAttribute("role", role); } if (sourceLines == null && !addMessages) { xmlOutput.openCloseTag(ELEMENT_NAME, attributeList); } else { xmlOutput.openTag(ELEMENT_NAME, attributeList); if (sourceLines != null) { sourceLines.writeXML(xmlOutput); } if (addMessages) { xmlOutput.openTag(MESSAGE_TAG); xmlOutput.writeText(this.toString()); xmlOutput.closeTag(MESSAGE_TAG); } xmlOutput.closeTag(ELEMENT_NAME); } }
static MethodAnnotation obfuscate(MethodAnnotation m) { String className = m.getClassName(); if (className.startsWith("java")) { return m; } String methodName = m.getMethodName(); String methodSignature = m.getMethodSignature(); if ("hashCode".equals(methodName) && "()I".equals(methodSignature) || "equals".equals(methodName) && "(Ljava/lang/Object;)Z".equals(methodSignature) || "compareTo".equals(methodName) && "(Ljava/lang/Object;)I".equals(methodSignature) || "<init>".equals(methodName) || "<clinit>".equals(methodName)) { // don't need to obfuscate method name } else { methodName = hashData(methodName); } MethodAnnotation result = new MethodAnnotation(hashClass(className), methodName, hashMethodSignature(methodSignature), m.isStatic()); result.setDescription(m.getDescription()); return result; }
public static XMethod createXMethod(MethodAnnotation ma) { return createXMethod(ma.getClassName(), ma.getMethodName(), ma.getMethodSignature(), ma.isStatic()); }
@Override public boolean match(BugInstance bugInstance) { MethodAnnotation methodAnnotation = null; if (role == null || "".equals(role)) { methodAnnotation = bugInstance.getPrimaryMethod(); } else { for (BugAnnotation a : bugInstance.getAnnotations()) { if (a instanceof MethodAnnotation && role.equals(a.getDescription())) { methodAnnotation = (MethodAnnotation) a; break; } } } if (methodAnnotation == null) { return false; } if (!name.match(methodAnnotation.getMethodName())) { return false; } if (signature != null && !signature.match(methodAnnotation.getMethodSignature())) { return false; } return true; }
public MethodDescriptor getMethodDescriptor(MethodAnnotation ma) { return getMethodDescriptor(ClassName.toSlashedClassName(ma.getClassName()), ma.getMethodName(), ma.getMethodSignature(), ma.isStatic()); }
/** * Rewrite a MethodAnnotation to update the class name, and any class names * mentioned in the method signature. * * @param classNameRewriter * a ClassNameRewriter * @param annotation * a MethodAnnotation * @return the possibly-rewritten MethodAnnotation */ public static MethodAnnotation convertMethodAnnotation(ClassNameRewriter classNameRewriter, MethodAnnotation annotation) { if (classNameRewriter != IdentityClassNameRewriter.instance()) { annotation = new MethodAnnotation(classNameRewriter.rewriteClassName(annotation.getClassName()), annotation.getMethodName(), rewriteMethodSignature(classNameRewriter, annotation.getMethodSignature()), annotation.isStatic()); } return annotation; }
@Override protected ActionResult doAccept(BugInstance issue, Ignore action) { final MethodAnnotation method = issue.getPrimaryMethod(); final String className = issue.getPrimaryClass().getClassName(); final String methodName = method == null ? null : method.getMethodName(); final Language language = Language.byFilename(issue.getPrimaryClass().getSourceFileName()); return action.accept(new NamedLocation(issue.getType(), language, className, methodName, true)); }
@Override protected ActionResult doAccept(BugInstance issue, Ignore action) { final MethodAnnotation method = issue.getPrimaryMethod(); final String className = issue.getPrimaryClass().getClassName(); final String methodName = method == null ? null : method.getMethodName(); final Language language = Language.byFilename(issue.getPrimaryClass().getSourceFileName()); return action.accept(new NamedLocation(issue.getType(), language, className, methodName, true)); }
@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); }
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { XMLAttributeList attributeList = new XMLAttributeList().addAttribute("classname", getClassName()) .addAttribute("name", getMethodName()).addAttribute("signature", getMethodSignature()) .addAttribute("isStatic", String.valueOf(isStatic())); if (isPrimary) { attributeList.addAttribute("primary", "true"); } String role = getDescription(); if (!DEFAULT_ROLE.equals(role)) { attributeList.addAttribute("role", role); } if (sourceLines == null && !addMessages) { xmlOutput.openCloseTag(ELEMENT_NAME, attributeList); } else { xmlOutput.openTag(ELEMENT_NAME, attributeList); if (sourceLines != null) { sourceLines.writeXML(xmlOutput); } if (addMessages) { xmlOutput.openTag(MESSAGE_TAG); xmlOutput.writeText(this.toString()); xmlOutput.closeTag(MESSAGE_TAG); } xmlOutput.closeTag(ELEMENT_NAME); } }