Examples of InvokeInstruction


Examples of com.subhajit.codeanalysis.reflection.InvokeInstruction

    }

    for (Instruction line : code) {
      if (line instanceof InvokeInstruction) {
        sLog.fine("InvokeInstruction - " + line.toString());
        InvokeInstruction destInvokeInstruction = (InvokeInstruction) line;
        final String invokedClassName = destInvokeInstruction
            .getInvokedClass();

        // Check if this is a class of interest.
        if (filters != null) {
          if (!checkPackageMatch(filters, invokedClassName)) {
            sLog
                .fine("Returning, since this class is not interesting.");
            continue;
          }
        }

        final ImmutableActor destActor = new ImmutableActor(
            generateSequenceDiagramActorRef(destInvokeInstruction),
            CommonUtils
                .getClassNameSansPackage(destInvokeInstruction
                    .getInvokedClass())
                + "."
                + destInvokeInstruction.getInvokedMethod());
        model.addMessage(new ImmutableMessage(srcActor, destActor,
            generateSequenceDiagramMessage(destInvokeInstruction),
            destInvokeInstruction.getInvokedMethodReturnType()));

        // Experimentally, at this point, add a sequence diagram model
        // for the destActor's invoked method.
        if (followMethodCalls) {
          sLog.fine(" method calls");
          try {
            MethodInfo destMethod = new MethodInfo(
                invokedClassName, destInvokeInstruction
                    .getInvokedMethod(),
                Utility.methodSignatureArgumentTypes(
                    destInvokeInstruction
                        .getInvokedMethodSignature(),
                    false),
                Utility.methodSignatureReturnType(
                    destInvokeInstruction
                        .getInvokedMethodSignature(),
                    false), null);

            if (!methodStack.contains(destMethod)) {
              // methodStack.add(destMethod);
View Full Code Here

Examples of com.subhajit.diagrams.codeanalysis.InvokeInstruction

    }

    for (Instruction line : code) {
      if (line instanceof InvokeInstruction) {
        sLog.fine("InvokeInstruction - " + line.toString());
        InvokeInstruction destInvokeInstruction = (InvokeInstruction) line;
        final String invokedClassName = destInvokeInstruction
            .getInvokedClass();

        // Check if this is a class of interest.
        if (filters != null) {
          if (!checkPackageMatch(filters, invokedClassName)) {
            sLog
                .fine("Returning, since this class is not interesting.");
            continue;
          }
        }

        final ImmutableActor destActor = new ImmutableActor(
            generateSequenceDiagramActorRef(destInvokeInstruction),
            CommonUtils
                .getClassNameSansPackage(destInvokeInstruction
                    .getInvokedClass())
                + "."
                + destInvokeInstruction.getInvokedMethod());
        model.addMessage(new ImmutableMessage(srcActor, destActor,
            generateSequenceDiagramMessage(destInvokeInstruction),
            destInvokeInstruction.getInvokedMethodReturnType()));

        // Experimentally, at this point, add a sequence diagram model
        // for the destActor's invoked method.
        if (followMethodCalls) {
          sLog.fine(" method calls");
          try {
            MethodInfo destMethod = new MethodInfo(
                invokedClassName, destInvokeInstruction
                    .getInvokedMethod(),
                Utility.methodSignatureArgumentTypes(
                    destInvokeInstruction
                        .getInvokedMethodSignature(),
                    false),
                Utility.methodSignatureReturnType(
                    destInvokeInstruction
                        .getInvokedMethodSignature(),
                    false), null);

            if (!methodStack.contains(destMethod)) {
              // methodStack.add(destMethod);
View Full Code Here

Examples of org.apache.bcel.generic.InvokeInstruction

        throws NoMatchingInvokeInterfaceInstruction {

        logger.info("Found a logger instruction.");
        InstructionHandle lastLogHandle = handle;

        InvokeInstruction invokeInterface = null;
        Instruction inst = null;
        while (true) {
            handle = handle.getNext();
            if (handle == null) {
                logger.warn("No matching invokeInterface found.");
                throw new NoMatchingInvokeInterfaceInstruction("No matching invokeInterface found.");
            }
            inst = handle.getInstruction();
            if (inst instanceof InvokeInstruction) {
                invokeInterface = (InvokeInstruction) inst;
                if (invokeInterface.getClassType(cp).equals(getLogType())) {
                    logger.info("Found matching invokeInstruction.");
                    if (level_logs == FORKLOGS) {
                        InstructionHandle insertHandle =
                            insertFork(il, lastLogHandle, handle, cp);
                        if (insertHandle != null) {
View Full Code Here

Examples of org.apache.bcel.generic.InvokeInstruction

        // If it's an InvokeInstruction, add declared exceptions and
        // RuntimeException
        if (ins instanceof InvokeInstruction) {
            ConstantPoolGen cpg = methodGen.getConstantPool();

            InvokeInstruction inv = (InvokeInstruction) ins;
            ObjectType[] declaredExceptionList = Hierarchy2.findDeclaredExceptions(inv, cpg);
            if (declaredExceptionList == null) {
                // Couldn't find declared exceptions,
                // so conservatively assume it could thrown any checked
                // exception.
View Full Code Here

Examples of org.apache.bcel.generic.InvokeInstruction

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            InstructionHandle handle = i.next().getHandle();
            Instruction ins = handle.getInstruction();

            if (ins instanceof InvokeInstruction) {
                InvokeInstruction inv = (InvokeInstruction) ins;
                Call call = new Call(inv.getClassName(cpg), inv.getName(cpg), inv.getSignature(cpg));
                callMap.put(handle, call);
            }
        }

        return callMap;
View Full Code Here

Examples of org.apache.bcel.generic.InvokeInstruction

        Instruction ins = handle.getInstruction();

        if ((ins instanceof INVOKEVIRTUAL) || (ins instanceof INVOKEINTERFACE)) {
            // Does this instruction close the stream?
            InvokeInstruction inv = (InvokeInstruction) ins;

            // It's a close if the invoked class is any subtype of the stream
            // base class.
            // (Basically, we may not see the exact original stream class,
            // even though it's the same instance.)

            return inv.getName(cpg).equals("close") && inv.getSignature(cpg).equals("()V");

        }

        return false;
    }
View Full Code Here

Examples of org.apache.bcel.generic.InvokeInstruction

        Instruction ins = handle.getInstruction();

        if ((ins instanceof INVOKEVIRTUAL) || (ins instanceof INVOKEINTERFACE)) {
            // Does this instruction close the stream?
            InvokeInstruction inv = (InvokeInstruction) ins;

            if (!frame.isValid() || !getInstanceValue(frame, inv, cpg).isInstance()) {
                return false;
            }

            // It's a close if the invoked class is any subtype of the stream
            // base class.
            // (Basically, we may not see the exact original stream class,
            // even though it's the same instance.)
            try {
                String classClosed = inv.getClassName(cpg);

                if (relatedType(classClosed) ) {
                    return true;
                }
                if (classClosed.equals("java.io.ObjectOutput")) {
View Full Code Here

Examples of org.apache.bcel.generic.InvokeInstruction

            Instruction ins = location.getHandle().getInstruction();
            if (!(ins instanceof InvokeInstruction)) {
                continue;
            }
            InvokeInstruction iins = (InvokeInstruction) ins;

            ConstantFrame frame = constantDataflow.getFactAtLocation(location);
            if (!frame.isValid()) {
                // This basic block is probably dead
                continue;
            }

            if (iins.getName(cpg).equals("getConnection")
                    && iins.getSignature(cpg).equals(
                            "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;")
                            && iins.getClassName(cpg).equals("java.sql.DriverManager")) {
                Constant operandValue = frame.getTopValue();
                if (operandValue.isConstantString()) {
                    String password = operandValue.getConstantString();
                    if (password.length() == 0) {
                        bugAccumulator.accumulateBug(new BugInstance(this, "DMI_EMPTY_DB_PASSWORD", NORMAL_PRIORITY)
                        .addClassAndMethod(methodGen, sourceFile), classContext, methodGen, sourceFile, location);
                    } else {
                        bugAccumulator.accumulateBug(new BugInstance(this, "DMI_CONSTANT_DB_PASSWORD", NORMAL_PRIORITY)
                        .addClassAndMethod(methodGen, sourceFile), classContext, methodGen, sourceFile, location);
                    }

                }
            }

            if (iins.getName(cpg).equals("substring") && iins.getSignature(cpg).equals("(I)Ljava/lang/String;")
                    && iins.getClassName(cpg).equals("java.lang.String")) {

                Constant operandValue = frame.getTopValue();
                if (!operandValue.isConstantInteger()) {
                    continue;
                }
                int v = operandValue.getConstantInt();
                if (v == 0) {
                    bugAccumulator.accumulateBug(new BugInstance(this, "DMI_USELESS_SUBSTRING", NORMAL_PRIORITY)
                    .addClassAndMethod(methodGen, sourceFile), classContext, methodGen, sourceFile, location);
                }

            } else if (iins.getName(cpg).equals("<init>") && iins.getSignature(cpg).equals("(Ljava/lang/String;)V")
                    && iins.getClassName(cpg).equals("java.io.File")) {

                Constant operandValue = frame.getTopValue();
                if (!operandValue.isConstantString()) {
                    continue;
                }
View Full Code Here

Examples of org.apache.bcel.generic.InvokeInstruction

        // See if the instruction is an InvokeInstruction
        Instruction ins = handle.getInstruction();
        if (!(ins instanceof InvokeInstruction)) {
            return null;
        }
        InvokeInstruction inv = (InvokeInstruction) ins;

        String methodName = inv.getMethodName(cpg);
        boolean isStatic = inv.getOpcode() == Constants.INVOKESTATIC;
        boolean isCtor = methodName.equals("<init>");

        int actualMode = 0;

        if (isStatic) {
            actualMode |= STATIC;
        }
        if (isCtor) {
            actualMode |= CONSTRUCTOR;
        }
        if (!isStatic && !isCtor) {
            actualMode |= INSTANCE;
        }

        // Intersection of actual and desired modes must be nonempty.
        if ((actualMode & mode) == 0) {
            return null;
        }

        // Check class name, method name, and method signature.
        if (!methodNameMatcher.match(methodName) || !methodSigMatcher.match(inv.getSignature(cpg))
                || !classNameMatcher.match(inv.getClassName(cpg))) {
            return null;
        }

        // It's a match!
        return new MatchResult(this, bindingSet);
View Full Code Here

Examples of org.apache.bcel.generic.InvokeInstruction

    }

    private void examineCallSite(Location location, ConstantPoolGen cpg, TypeDataflow typeDataflow)
            throws DataflowAnalysisException, CFGBuilderException, ClassNotFoundException {

        InvokeInstruction invokeInstruction = (InvokeInstruction) location.getHandle().getInstruction();

        String methodName = invokeInstruction.getName(cpg);
        String signature = invokeInstruction.getSignature(cpg);

        // Don't check equals() calls.
        // If an equals() call unconditionally dereferences the parameter,
        // it is the fault of the method, not the caller.
        if (methodName.equals("equals") && signature.equals("(Ljava/lang/Object;)Z")) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.