public @CheckForNull MethodAnnotation getMethodCalledAnnotation(ConstantPoolGen cpg, InvokeInstruction inv) { MethodDescriptor invokedMethod = getInvokedMethod(cpg, inv); boolean standardEquals = "equals".equals(invokedMethod.getName()) && "(Ljava/lang/Object;)Z".equals(invokedMethod.getSignature()) && !invokedMethod.isStatic(); return standardEquals ? null : MethodAnnotation.fromMethodDescriptor(invokedMethod); }
/** * @param m method to check * @return true if we may assume that given unseen method has no side effect */ private static boolean hasNoSideEffectUnknown(MethodDescriptor m) { if(m.isStatic() && m.getName().equals(Const.STATIC_INITIALIZER_NAME)) { // No side effect for class initializer of unseen class return true; } if(!m.isStatic() && m.getName().equals("toString") && m.getSignature().equals("()Ljava/lang/String;")) { // We assume no side effect for unseen toString methods return true; } if(!m.isStatic() && m.getName().equals("hashCode") && m.getSignature().equals("()I")) { // We assume no side effect for unseen hashCode methods return true; } if(m.isStatic() && m.getName().equals("values") && m.getSignature().startsWith("()")) { // We assume no side effect for unseen enums return Subtypes2.instanceOf(m.getClassDescriptor(), "java.lang.Enum"); } return false; }
@Override public boolean shouldVisitCode(Code obj) { return !getMethodDescriptor().isStatic() && ((isComparator && getMethodName().equals("compare") && getMethodSig().endsWith(")I")) || ((getMethodName() .equals("compareTo") && getMethodSig().equals("(L"+getClassName()+";)I")))); }
protected UnresolvedXMethod(MethodDescriptor m) { super(m.getClassDescriptor().getDottedClassName(), m.getName(), m.getSignature(), m.isStatic() ? Const.ACC_STATIC : 0); if (XFactory.DEBUG_UNRESOLVED) { System.out.println("Unresolved xmethod: " + this); } }
@Override public XMethod findMatchingMethod(MethodDescriptor descriptor) { return findMethod(descriptor.getName(), descriptor.getSignature(), descriptor.isStatic()); }
/** * @param m method to check * @return true if given method is known to change its object only */ private static boolean isObjectOnlyMethod(MethodDescriptor m) { if (m.isStatic() || m.getName().equals(Const.CONSTRUCTOR_NAME) || m.getName().equals("forEach")) { return false; } String className = m.getSlashedClassName(); if(isObjectOnlyClass(className)) { return true; } if(className.startsWith("javax/xml/") && m.getName().startsWith("next")) { return true; } if ((className.startsWith("java/net/") || className.startsWith("javax/servlet")) && (m.getName().startsWith("remove") || m.getName().startsWith("add") || m.getName().startsWith("set"))) { return true; } if(OBJECT_ONLY_METHODS.contains(m)) { return true; } return false; }
private static Map<Integer, Value> getParameterTypes(MethodDescriptor descriptor) { Type[] argumentTypes = Type.getArgumentTypes(descriptor.getSignature()); int j = 0; Map<Integer, Value> result = new HashMap<>(); if(!descriptor.isStatic()) { result.put(j++, new Value("this", null, "L"+descriptor.getSlashedClassName()+";")); } for (int i = 0; i < argumentTypes.length; i++) { result.put(j, new Value("arg"+i, null, argumentTypes[i].getSignature())); j += argumentTypes[i].getSize(); } return result; }
/** * Create a MethodAnnotation from a MethodDescriptor. * * @param methodDescriptor * the MethodDescriptor * @return the MethodAnnotation */ public static MethodAnnotation fromMethodDescriptor(MethodDescriptor methodDescriptor) { return fromForeignMethod(methodDescriptor.getSlashedClassName(), methodDescriptor.getName(), methodDescriptor.getSignature(), methodDescriptor.isStatic()); }
for(MethodCall call : entry.getValue()) { uselessVoidCandidate = false; if((call.getMethod().equals(method) && call.getTarget() == TARGET_THIS) || method.isStatic()) { uselessVoidCandidate = true; } else {
static List<Item> getInitialLocals(MethodDescriptor descriptor) { List<Item> locals = new ArrayList<>(); Type[] argTypes = Type.getArgumentTypes(descriptor.getSignature()); int reg = 0; if (!descriptor.isStatic()) { Item it = Item.typeOnly("L" + descriptor.getSlashedClassName() + ";"); locals.add(it); reg += it.getSize(); } for (Type argType : argTypes) { Item it = Item.typeOnly(argType.getSignature()); locals.add(it); reg += it.getSize(); if (it.usesTwoSlots()) { locals.add(null); } } return locals; }
return !m.getSignature().startsWith("(Ljava/lang/String;"); if(!m.isStatic() && m.getName().equals("equals") && m.getSignature().equals("(Ljava/lang/Object;)Z")) { return true;
/** * Constructor. * * @param methodDescriptor * the MethodDescriptor indicating the method it is unprofitable * to analyze */ public MethodUnprofitableException(MethodDescriptor methodDescriptor) { super("Appears unprofitable to analyze " + methodDescriptor.toString()); this.method = XFactory.createXMethod(methodDescriptor.getClassDescriptor().toDottedClassName(), methodDescriptor.getName(), methodDescriptor.getSignature(), methodDescriptor.isStatic()); }
public MatchMethodEntry(MethodDescriptor method, ObligationPolicyDatabaseActionType action, ObligationPolicyDatabaseEntryType entryType, Obligation... obligations) { this(new SubtypeTypeMatcher(method.getClassDescriptor()), new ExactStringMatcher(method.getName()), new ExactStringMatcher(method.getSignature()), method.isStatic(), action, entryType, obligations); }
Set<String> sideEffectClinit = new HashSet<>(); for(Entry<MethodDescriptor, SideEffectStatus> entry : statusMap.entrySet()) { if (entry.getValue() == SideEffectStatus.SIDE_EFFECT && entry.getKey().isStatic() && entry.getKey().getName().equals(Const.STATIC_INITIALIZER_NAME)) { sideEffectClinit.add(entry.getKey().getSlashedClassName()); if (m.isStatic() || m.getName().equals(Const.CONSTRUCTOR_NAME)) { if(sideEffectClinit.contains(m.getSlashedClassName())) { continue; if (m.isStatic() && getStaticMethods.contains(m) && !m.getSlashedClassName().startsWith("java/")) { String returnSlashedClassName = ClassName.fromFieldSignature(returnType); if(returnSlashedClassName != null) {
desc.getSignature(), desc.isStatic());
if (!methodDescriptor.isStatic()) {
private void reportWarning(Obligation obligation, State state, StateSet factAtExit) { String className = obligation.getClassName(); if (methodDescriptor.isStatic() && "main".equals(methodDescriptor.getName()) && "([Ljava/lang/String;)V".equals(methodDescriptor.getSignature()) && (className.contains("InputStream") || className.contains("Reader") || factAtExit.isOnExceptionPath())) {
private MethodCall getMethodCall(MethodDescriptor methodDescriptorOperand) { Item objItem = getStack().getStackItem(getNumberArguments(methodDescriptorOperand.getSignature())); if (isNew(objItem)) { return new MethodCall(methodDescriptorOperand, TARGET_NEW); } if (objItem.getRegisterNumber() == 0 && !getMethod().isStatic()) { return new MethodCall(methodDescriptorOperand, constructor ? TARGET_NEW : TARGET_THIS); } XField xField = objItem.getXField(); if (xField != null) { if (classInit && xField.isStatic() && xField.getClassDescriptor().getClassName().equals(getClassName())) { return new MethodCall(methodDescriptorOperand, TARGET_NEW); } if (!getMethodDescriptor().isStatic() && objItem.getFieldLoadedFromRegister() == 0 && allowedFields.contains(xField.getFieldDescriptor())) { fieldsModifyingMethods.add(getMethodDescriptor()); return new MethodCall(methodDescriptorOperand, xField.getFieldDescriptor()); } } return new MethodCall(methodDescriptorOperand, TARGET_OTHER); }
@Override public boolean shouldVisitCode(Code obj) { return !getMethodDescriptor().isStatic() && ((isComparator && getMethodName().equals("compare") && getMethodSig().endsWith(")I")) || ((getMethodName() .equals("compareTo") && getMethodSig().equals("(L"+getClassName()+";)I")))); }
protected UnresolvedXMethod(MethodDescriptor m) { super(m.getClassDescriptor().getDottedClassName(), m.getName(), m.getSignature(), m.isStatic() ? Constants.ACC_STATIC : 0); if (XFactory.DEBUG_UNRESOLVED) { System.out.println("Unresolved xmethod: " + this); } }