Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.Type


        if (frame.getStackDepth() < 2) {
            throw new DataflowAnalysisException("Stack underflow", methodGen, handle);
        }

        int numSlots = frame.getNumSlots();
        Type lhsType = frame.getValue(numSlots - 2);
        Type rhsType = frame.getValue(numSlots - 1);

        if (lhsType instanceof NullType || rhsType instanceof NullType) {
            return;
        }
        if (lhsType instanceof ReferenceType && rhsType instanceof ReferenceType) {
            IncompatibleTypes result = IncompatibleTypes.getPriorityForAssumingCompatible(lhsType, rhsType, true);
            if (result != IncompatibleTypes.SEEMS_OK && result != IncompatibleTypes.UNCHECKED) {
                String sourceFile = jclass.getSourceFileName();

                boolean isAssertSame = handle.getInstruction() instanceof INVOKESTATIC;
                if (isAssertSame) {
                    if(testingEnabled) {
                        bugAccumulator.accumulateBug(
                                new BugInstance(this, "TESTING", result.getPriority())
                                .addClassAndMethod(methodGen, sourceFile)
                                .addString("Calling assertSame with two distinct objects")
                                .addFoundAndExpectedType(rhsType, lhsType)
                                .addSomeSourceForTopTwoStackValues(classContext, method, location),
                                SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, handle));
                    }
                } else {
                    bugAccumulator.accumulateBug(
                            new BugInstance(this, "EC_UNRELATED_TYPES_USING_POINTER_EQUALITY", result.getPriority())
                            .addClassAndMethod(methodGen, sourceFile).addFoundAndExpectedType(rhsType, lhsType)
                            .addSomeSourceForTopTwoStackValues(classContext, method, location),
                            SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, handle));
                }
                return;
            }
            if (lhsType.equals(Type.OBJECT) && rhsType.equals(Type.OBJECT)) {
                return;
            }
            String lhs = SignatureConverter.convert(lhsType.getSignature());
            String rhs = SignatureConverter.convert(rhsType.getSignature());

            if (lhs.equals("java.lang.String") || rhs.equals("java.lang.String")) {
                handleStringComparison(jclass, method, methodGen, visitor, stringComparisonList, location, lhsType, rhsType);
            } else if (suspiciousSet.contains(lhs)) {
                handleSuspiciousRefComparison(jclass, method, methodGen, refComparisonList, location, lhs,
View Full Code Here


        if (frame.getStackDepth() < 2) {
            throw new DataflowAnalysisException("Stack underflow", methodGen, handle);
        }

        int numSlots = frame.getNumSlots();
        Type lhsType_ = frame.getValue(numSlots - 2);
        Type rhsType_ = frame.getValue(numSlots - 1);

        // Ignore top and bottom values
        if (lhsType_.getType() == T_TOP || lhsType_.getType() == T_BOTTOM || rhsType_.getType() == T_TOP
                || rhsType_.getType() == T_BOTTOM) {
            return;
        }
        InvokeInstruction inv = (InvokeInstruction) handle.getInstruction();
        MethodAnnotation calledMethodAnnotation = getMethodCalledAnnotation(cpg, inv);
        boolean looksLikeTestCase = TestCaseDetector.likelyTestCase(XFactory.createXMethod(methodGen));
        int priorityModifier = 0;
        if (looksLikeTestCase) {
            priorityModifier = 1;
        }

        if (rhsType_.getType() == T_NULL) {
            // A literal null value was passed directly to equals().
            if (!looksLikeTestCase) {

                try {
                    IsNullValueDataflow isNullDataflow = classContext.getIsNullValueDataflow(method);
                    IsNullValueFrame isNullFrame = isNullDataflow.getFactAtLocation(location);
                    BugAnnotation a = BugInstance.getSourceForTopStackValue(classContext, method, location);
                    int priority = NORMAL_PRIORITY;
                    if (a instanceof FieldAnnotation && ((FieldAnnotation) a).isStatic()) {
                        priority = LOW_PRIORITY;
                    }
                    if (isNullFrame.isValid() && isNullFrame.getTopValue().isDefinitelyNull()) {
                        String type = "EC_NULL_ARG";
                        if (calledMethodAnnotation != null && calledMethodAnnotation.isStatic()){
                            type = "DMI_DOH";
                            priority = LOW_PRIORITY;
                        }
                        BugInstance bug = new BugInstance(this, type, priority + priorityModifier).addClassAndMethod(methodGen, sourceFile)
                                .addOptionalAnnotation(calledMethodAnnotation);
                        if (type.equals("DMI_DOH")) {
                            bug.addString("Use \"== null\" to check for a value being null");
                        }
                        bugAccumulator.accumulateBug(
                                bug,
                                SourceLineAnnotation.fromVisitedInstruction(this.classContext, methodGen, sourceFile,
                                        location.getHandle()));
                    }
                } catch (CFGBuilderException e) {
                    AnalysisContext.logError("Error getting null value analysis", e);
                }

            }
            return;
        } else if (lhsType_.getType() == T_NULL) {
            // Hmm...in this case, equals() is being invoked on
            // a literal null value. This is really the
            // purview of FindNullDeref. So, we'll just do nothing.
            return;
        } else if (!(lhsType_ instanceof ReferenceType) || !(rhsType_ instanceof ReferenceType)) {
            bugReporter.logError("equals() used to compare non-object type(s) " + lhsType_ + " and " + rhsType_ + " in "
                    + SignatureConverter.convertMethodSignature(methodGen) + " at " + location.getHandle());
            return;
        }
        IncompatibleTypes result = IncompatibleTypes.getPriorityForAssumingCompatible(lhsType_, rhsType_);

        if (lhsType_ instanceof ArrayType && rhsType_ instanceof ArrayType) {
            String pattern = "EC_BAD_ARRAY_COMPARE";
            IncompatibleTypes result2 = IncompatibleTypes.getPriorityForAssumingCompatible(lhsType_, rhsType_, true);
            if (result2.getPriority() <= Priorities.NORMAL_PRIORITY) {
                pattern = "EC_INCOMPATIBLE_ARRAY_COMPARE";
            } else if (calledMethodAnnotation != null && calledMethodAnnotation.getClassName().equals("org.testng.Assert")) {
                return;
            }
            bugAccumulator.accumulateBug(new BugInstance(this, pattern, NORMAL_PRIORITY).addClassAndMethod(methodGen, sourceFile)
                    .addFoundAndExpectedType(rhsType_, lhsType_)
                    .addSomeSourceForTopTwoStackValues(classContext, method, location)
                    .addOptionalAnnotation(calledMethodAnnotation, MethodAnnotation.METHOD_CALLED),
                    SourceLineAnnotation.fromVisitedInstruction(this.classContext, methodGen, sourceFile, location.getHandle()));
            return;
        }

        if (result.getPriority() >= Priorities.LOW_PRIORITY) {
            addEqualsCheck(lhsType_.getSignature(), handle.getPosition());
            addEqualsCheck(rhsType_.getSignature(), handle.getPosition());
        }

        if (result == IncompatibleTypes.SEEMS_OK) {
            return;
        }


        if (result.getPriority() > Priorities.LOW_PRIORITY) {
            return;
        }

        if (result == IncompatibleTypes.ARRAY_AND_NON_ARRAY || result == IncompatibleTypes.ARRAY_AND_OBJECT) {
            String lhsSig = lhsType_.getSignature();
            String rhsSig = rhsType_.getSignature();
            boolean allOk = checkForWeirdEquals(lhsSig, rhsSig, new HashSet<XMethod>());
            if (allOk) {
                priorityModifier += 2;
            }
            bugAccumulator.accumulateBug(new BugInstance(this, "EC_ARRAY_AND_NONARRAY", result.getPriority() + priorityModifier)
            .addClassAndMethod(methodGen, sourceFile).addFoundAndExpectedType(rhsType_, lhsType_)
            .addSomeSourceForTopTwoStackValues(classContext, method, location)
            .addOptionalAnnotation(calledMethodAnnotation, MethodAnnotation.METHOD_CALLED),
            SourceLineAnnotation.fromVisitedInstruction(this.classContext, methodGen, sourceFile, location.getHandle()));
        } else if (result == IncompatibleTypes.INCOMPATIBLE_CLASSES) {
            String lhsSig = lhsType_.getSignature();
            String rhsSig = rhsType_.getSignature();
            boolean core = lhsSig.startsWith("Ljava") && rhsSig.startsWith("Ljava");
            if (core) {
                looksLikeTestCase = false;
                priorityModifier = 0;
            }
View Full Code Here

        @Override
        public void initEntryFact(TypeFrame result) {
            super.initEntryFact(result);
            for (int i = 0; i < methodGen.getMaxLocals(); i++) {
                Type t = result.getValue(i);
                if (t.equals(Type.STRING)) {
                    result.setValue(i, parameterStringTypeInstance);
                }
            }
        }
View Full Code Here

            // Constructor - obligation type is the type of object being created
            // (or some supertype)
            createdObligation = database.getFactory().getObligationByType(xmethod.getClassDescriptor());
        } else {
            // Factory method - obligation type is the return type
            Type returnType = Type.getReturnType(xmethod.getSignature());
            if (returnType instanceof ObjectType) {
                try {
                    createdObligation = database.getFactory().getObligationByType((ObjectType) returnType);
                } catch (ClassNotFoundException e) {
                    reporter.reportMissingClass(e);
View Full Code Here

        Constants.CONSTANT_NameAndType);

    String signature = cnat.getSignature(_cp);

    if (method) {
      Type type = Type.getReturnType(signature);

      checkType(type);

      Type[] types = Type.getArgumentTypes(signature);
View Full Code Here

                    for (XField of : outerXClass.getXFields()) {
                        if (!of.isStatic()) {
                            String sourceSignature = of.getSourceSignature();
                            if (sourceSignature != null && of.getSignature().equals("Ljava/lang/ThreadLocal;")) {
                                Type ofType = GenericUtilities.getType(sourceSignature);
                                if (ofType instanceof GenericObjectType) {
                                    GenericObjectType gType = (GenericObjectType) ofType;

                                    for (ReferenceType r : gType.getParameters()) {
                                        if (r instanceof ObjectType) {
View Full Code Here

        locals[i] = ((UninitializedObjectType) locals[i]).getInitialized();
      }
    }
    if ((locals[i] instanceof ReferenceType) && (lv.locals[i] instanceof ReferenceType)){
      if (! locals[i].equals(lv.locals[i])){ // needed in case of two UninitializedObjectType instances
        Type sup = ((ReferenceType) locals[i]).firstCommonSuperclass((ReferenceType) (lv.locals[i]));

        if (sup != null){
          locals[i] = sup;
        }
        else{
View Full Code Here

            implementation.append(factory.createCheckCast((ReferenceType)invokeSignature[i]));
         }
      }

      Class returnClass = method.getReturnType();
      Type returnType = convertClassToType(returnClass);

      // On the stack we now have the casted mbean and all the casted arguments, invoke
      implementation.append(factory.createInvoke(management, method.getName(), returnType, invokeSignature, Constants.INVOKEINTERFACE));

      if (returnClass == Void.TYPE)
View Full Code Here

         while ((c = cls.getComponentType()) != null)
         {
            ++dimensions;
            cls = c;
         }
         Type t = convertClassToType(cls);
         return new ArrayType(t, dimensions);
      }
      return new ObjectType(cls.getName());
   }
View Full Code Here

      new StringBuffer( getModifierString( modifiers ) );
    String conc = "";

    // handle return type
    buffer.append( " " );
    Type returnType = Type.getReturnType( methodSignature );
    buffer.append( returnType.toString() );
    buffer.append( " " );
   
    // handle class name
    if( !chopClassName ) {
      buffer.append( className );
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.Type

Copyright © 2018 www.massapicom. 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.