Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.FieldInstruction


     */
    private void checkNonNullPutField(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact)
            throws DataflowAnalysisException {
        INullnessAnnotationDatabase database = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase();

        FieldInstruction fieldIns = (FieldInstruction) location.getHandle().getInstruction();

        XField field = XFactory.createXField(fieldIns, methodGen.getConstantPool());
        char firstChar = field.getSignature().charAt(0);
        if (firstChar != 'L' && firstChar != '[') {
            return;
View Full Code Here


    public MatchResult match(InstructionHandle handle, ConstantPoolGen cpg, ValueNumberFrame before, ValueNumberFrame after,
            BindingSet bindingSet) throws DataflowAnalysisException {

        Variable field;
        Instruction ins = handle.getInstruction();
        FieldInstruction fieldIns;

        // The instruction must be GETFIELD or GETSTATIC
        if (ins instanceof GETFIELD) {
            fieldIns = (GETFIELD) ins;
            ValueNumber ref = before.getTopValue();
            field = new FieldVariable(ref, fieldIns.getClassName(cpg), fieldIns.getFieldName(cpg), fieldIns.getSignature(cpg));
        } else if (ins instanceof GETSTATIC) {
            fieldIns = (GETSTATIC) ins;
            field = new FieldVariable(fieldIns.getClassName(cpg), fieldIns.getFieldName(cpg), fieldIns.getSignature(cpg));
        } else {
            return null;
        }

        Variable result = snarfFieldValue(fieldIns, cpg, after);
View Full Code Here

            if (iins.getMethodName(cpg).equals("close") && iins.getSignature(cpg).equals("()V")) {
                propertySet.addProperty(NullDerefProperty.CLOSING_NULL);
            }
        } else if (ins instanceof FieldInstruction) {
            FieldInstruction fins = (FieldInstruction) ins;
            XField referencedField = XFactory.createXField(fins, cpg);
            cause = FieldAnnotation.fromXField(referencedField);

        } else {
            cause = new StringAnnotation(ins.getName());
View Full Code Here

                    InstructionHandle n = location.getHandle().getNext();
                    isNullCheck = n.getInstruction() instanceof IFNONNULL || n.getInstruction() instanceof IFNULL;
                    if (DEBUG && isNullCheck) {
                        System.out.println("is null check");
                    }
                    FieldInstruction fins = (FieldInstruction) ins;
                    xfield = Hierarchy.findXField(fins, cpg);
                    if (xfield == null) {
                        continue;
                    }
                    isWrite = ins.getOpcode() == Constants.PUTFIELD;
                    isLocal = fins.getClassName(cpg).equals(classContext.getJavaClass().getClassName());
                    if (DEBUG) {
                        System.out.println("Handling field access: " + location.getHandle() + " (frame="
                                + vnaDataflow.getFactAtLocation(location) + ") :" + n);
                    }
                } else if (ins instanceof INVOKESTATIC) {
View Full Code Here

            Instruction i = ih.getInstruction();

            if ((i instanceof GETFIELD) || (i instanceof PUTFIELD))
            {
                Field f;
                FieldInstruction field = (FieldInstruction) i;
                Constant c = m.getConstantPool().getConstant(field.getIndex());
                ConstantFieldref fieldRef = (ConstantFieldref) c;

                ConstantClass cclass = (ConstantClass) m.getConstantPool().getConstant(fieldRef.getClassIndex());
                ConstantUtf8 utfClassName = (ConstantUtf8) m.getConstantPool().getConstant(cclass.getNameIndex());
                String utfClassNameString = StringUtils.replaceAll(utfClassName.getBytes().toString(), "/", ".");
                JavaClass fieldJavaClass = null;
                try
                {
                    fieldJavaClass = Repository.lookupClass(utfClassNameString);
                }
                catch (Throwable ex)
                {
                    // catch Throwable, so it is compatible with latest BCEL changes in methods signature.
                    // It nows raises ClassNotFoundException. In order to be able to compible this code
                    // with bcel-5.1 or bcel-5.1+, we catch as throwable
                    JPOXLogger.ENHANCER.error(LOCALISER.msg("Enhancer.ClassNotFound", utfClassNameString, ex));
                    throw new JDOFatalException(LOCALISER.msg("Enhancer.ClassNotFound", utfClassNameString, ex));
                }
                if (fieldJavaClass == null)
                {
                    throw new JDOFatalException(LOCALISER.msg("Enhancer.ClassNotFound", utfClassNameString,
                        new NullPointerException()));
                }

                f = BCELUtils.getFieldByName(field.getName(constantPoolGen), fieldJavaClass);
                if (f == null)
                {
                    String message = LOCALISER.msg("Enhancer.FieldIsNull", className, m.getName(), field.getName(constantPoolGen));
                    JPOXLogger.ENHANCER.error(message);
                    throw new NullPointerException(message);
                }

                ClassGen cg = BCELUtils.getClassByFieldByName(field.getName(constantPoolGen), fieldJavaClass);
                BCELFieldPropertyMetaData fieldConfig = null;
                BCELClassMetaData jdoConfigClass = ((BCELClassMetaData) cmd);

                // the accessing class is not this
                if (!cg.getClassName().equals(newClass.getClassName()))
                {
                    jdoConfigClass = (BCELClassMetaData) cmd.getPackageMetaData().getFileMetaData().getMetaDataManager().getMetaDataForClass(
                        cg.getClassName(), clr);
                }
                if( jdoConfigClass != null )
                {
                    AbstractMemberMetaData apmd = jdoConfigClass.findField(f);

                    if (apmd == null)
                    {
                        //check if a property(getter,setter) exists with this field name
                        if( jdoConfigClass.findProperty(f)==null )
                        {
                            //no fields netiher properties in the class, so something is wrong
                            String message = LOCALISER.msg("Enhancer.FieldConfigIsNullError", className + "." + f.getName());
                            JPOXLogger.ENHANCER.fatal(message);
                            throw new RuntimeException(message);
                        }
                    }
                    if( apmd != null && apmd.getPersistenceModifier() != FieldPersistenceModifier.NONE )
                    {
                        // do nothing
                    }
                    if (!isFieldAccessInPersistenceCapableClass(ih, m.getConstantPool()))
                    {
                        // do nothing
                    }
                    else if (fieldConfig != null && fieldConfig.getJdoFieldFlag() == 0)
                    {
                        // do nothing
                    }
                    else if (f.isStatic() || f.isFinal())
                    {
                        // do nothing
                    }
                    else if (BCELUtils.isSynthetic(f))
                    {
                        // do nothing
                    }
                    else
                    {
                        if (isDebugEnabled)
                        {
                            JPOXLogger.ENHANCER.debug(LOCALISER.msg("Enhancer.EnhanceOriginalMethod",
                                className + "." + m.getName(), f.getName()));
                        }
                        if( apmd != null && !apmd.isProperty() && apmd.getPersistenceModifier() != FieldPersistenceModifier.NONE)
                        {
                            //properties do not use jdoXXX methods
                            if (i instanceof GETFIELD)
                            {
                                ih.setInstruction(factory.createInvoke(cg.getClassName(), "jdo" + BCELUtils.getGetterName(f),
                                    field.getType(constantPoolGen), new Type[]{new ObjectType(cg.getClassName())}, Constants.INVOKESTATIC));
                            }
                            else
                            {
                                ih.setInstruction(factory.createInvoke(cg.getClassName(), "jdo" + BCELUtils.getSetterName(f),
                                    Type.VOID, new Type[]{new ObjectType(cg.getClassName()), field.getType(constantPoolGen)},
                                    Constants.INVOKESTATIC));
                            }
                            change = true;
                        }
                    }
View Full Code Here

        Class fieldTypeClass = field.getType();
        Type fieldType = computeType(fieldTypeClass);
        pushAndConvertValueArg(instructionList, instructionFactory,
                               fieldTypeClass, fieldType);

        FieldInstruction fieldInstruction = null;
        if (Modifier.isStatic(field.getModifiers())) {
            fieldInstruction =
                instructionFactory.createPutStatic(declaringClassName, field.getName(),
                                                   fieldType);
        }
View Full Code Here

        InstructionHandle[] ihs = il.getInstructionHandles();

        for (int j = 0; j < ihs.length; j++) {
            Instruction i = ihs[j].getInstruction();
            if (i instanceof GETSTATIC || i instanceof PUTSTATIC) {
                FieldInstruction g = (FieldInstruction)i;
                String s = g.getClassName(cp);
                int index = g.getIndex();
                ConstantFieldref cfr =(ConstantFieldref)cp.getConstant(index);
                int classIndex = cfr.getClassIndex();
                if (oldClass.equals(s)) {
                    int newIndex = cp.addClass(newClass);
                    cfr.setClassIndex(newIndex);
View Full Code Here

                InstructionList il = mg.getInstructionList();
                InstructionHandle ih = il.getStart();

                // get the current field instruction
                FieldInstruction currentGetFieldIns = null;

                // search for all GETFIELD and PUTFIELD instructions and
                // inserts the pre and post advices
                // handle GETFIELD followed by INVOKEINTERFACE on Collection like carrefully
                while (ih != null) {
                    Instruction ins = ih.getInstruction();

                    // handle the java.util.Collection classes
                    if (ins instanceof GETFIELD) {
                        FieldInstruction checkMe = (FieldInstruction)ins;
                        // if the field is an added join point field => skip it
                        // needed if a field of type collection is both setField
                        // and getField advised
                        if (!checkMe.getFieldName(cpg).startsWith(TransformationUtil.JOIN_POINT_PREFIX)) {
                            currentGetFieldIns = checkMe;
                            Instruction next = ih.getNext().getInstruction();
                            if (next instanceof INVOKEINTERFACE) {
                                // handle the INVOKEINTERFACE instruction
                                final InvokeInstruction invokeIns = (InvokeInstruction)next;

                                // do we have a collection?
                                if (invokeIns.getClassName(cpg).equals("java.util.Collection") ||
                                        invokeIns.getClassName(cpg).equals("java.util.Enumeration") ||
                                        invokeIns.getClassName(cpg).equals("java.util.Iterator") ||
                                        invokeIns.getClassName(cpg).equals("java.util.List") ||
                                        invokeIns.getClassName(cpg).equals("java.util.Map") ||
                                        invokeIns.getClassName(cpg).equals("java.util.Set") ||
                                        invokeIns.getClassName(cpg).equals("java.util.SortedMap") ||
                                        invokeIns.getClassName(cpg).equals("java.util.SortedSet")) {

                                    String methodName = invokeIns.getName(cpg);

                                    // is the collection modified (not only accessed or single PUTFIELD instr)?
                                    if (methodName.equals("add") ||
                                            methodName.equals("addAll") ||
                                            methodName.equals("set") ||
                                            methodName.equals("remove") ||
                                            methodName.equals("removeAll") ||
                                            methodName.equals("retainAll") ||
                                            methodName.equals("clear") ||
                                            methodName.equals("put") ||
                                            methodName.equals("putAll")) {

                                        final String fieldName = currentGetFieldIns.getName(cpg);
                                        final String signature = currentGetFieldIns.getFieldType(cpg).
                                                toString() + " " + fieldName;
                                        final Type joinPointType = TransformationUtil.MEMBER_FIELD_SET_JOIN_POINT_TYPE;

                                        FieldMetaData fieldMetaData =
                                                BcelMetaDataMaker.createFieldMetaData(currentGetFieldIns, cpg);

                                        String uuid = setFieldFilter(definition, classMetaData, fieldMetaData);

                                        // do we have to set a joinpoint ?
                                        if (uuid != null) {
                                            final String fieldClassName = currentGetFieldIns.getClassName(cpg);

                                            if (fieldClassName.equals(cg.getClassName())) {
                                                isMethodAdvised = true;

                                                insertPreAdvice(
                                                        il, ih, cg, fieldName,
                                                        factory, joinPointType);

                                                insertPostAdvice(
                                                        il, ih.getNext().getNext(), cg,
                                                        fieldName, factory, joinPointType);

                                                // store the join point field data
                                                JoinPointFieldData data = new JoinPointFieldData(
                                                        fieldName, signature, joinPointType, uuid);
                                                if (!setFieldJoinPoints.contains(data)) {
                                                    setFieldJoinPoints.add(data);
                                                }

                                                // add one step more to the InstructionList (GETFIELD(current) INVOKEINTERFACE with jp)
                                                ih = ih.getNext();
                                                ins = ih.getInstruction();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // handle the getField instructions
                    // (if we have set a getfield for collection modification jp the ins has been altered)
                    if (ins instanceof GETFIELD) {
                        final FieldInstruction gfIns = (FieldInstruction)ins;

                        String fieldName = gfIns.getName(cpg);
                        String signature = gfIns.getFieldType(cpg).toString() + " " + fieldName;
                        Type joinPointType = TransformationUtil.MEMBER_FIELD_GET_JOIN_POINT_TYPE;

                        FieldMetaData fieldMetaData = BcelMetaDataMaker.createFieldMetaData(gfIns, cpg);

                        String uuid = getFieldFilter(definition, classMetaData, fieldMetaData);
                        if (uuid != null) {

                            final String fieldClassName = gfIns.getClassName(cpg);
                            if (fieldClassName.equals(cg.getClassName())) {

                                isMethodAdvised = true;

                                insertPreAdvice(
                                        il, ih, cg, fieldName,
                                        factory, joinPointType);

                                insertPostAdvice(
                                        il, ih.getNext(), cg,
                                        fieldName, factory, joinPointType);

                                // store the join point field data
                                JoinPointFieldData data = new JoinPointFieldData(
                                        fieldName, signature, joinPointType, uuid);

                                if (!getFieldJoinPoints.contains(data)) {
                                    getFieldJoinPoints.add(data);
                                }
                            }
                        }
                    }
                    // handle the setField instructions
                    else if (ins instanceof PUTFIELD) {
                        final FieldInstruction pfIns = (FieldInstruction)ins;

                        String fieldName = pfIns.getName(cpg);
                        String signature = pfIns.getFieldType(cpg).toString() + " " + fieldName;
                        Type joinPointType = TransformationUtil.MEMBER_FIELD_SET_JOIN_POINT_TYPE;

                        FieldMetaData fieldMetaData =
                                BcelMetaDataMaker.createFieldMetaData(pfIns, cpg);

                        String uuid = setFieldFilter(definition, classMetaData, fieldMetaData);
                        if (uuid != null) {

                            final String fieldClassName = pfIns.getClassName(cpg);
                            if (fieldClassName.equals(cg.getClassName())) {

                                isMethodAdvised = true;

                                insertPreAdvice(
View Full Code Here

            // inserts the pre and post advices
            while (ih != null) {
                Instruction ins = ih.getInstruction();

                if (ins instanceof GETFIELD || ins instanceof GETSTATIC) {
                    FieldInstruction gfIns = (FieldInstruction)ins;

                    String fieldName = gfIns.getName(cpg);
                    String signature = gfIns.getFieldType(cpg).toString() + " " + fieldName;
                    Type joinPointType = TransformationUtil.STATIC_FIELD_GET_JOIN_POINT_TYPE;
                    String joinPointClass = TransformationUtil.STATIC_FIELD_GET_JOIN_POINT_CLASS;

                    FieldMetaData fieldMetaData =
                            BcelMetaDataMaker.createFieldMetaData(gfIns, cpg);

                    String uuid = getFieldFilter(classMetaData, fieldMetaData);
                    if (uuid != null) {

                        String fieldClassName = gfIns.getClassName(cpg);
                        if (fieldClassName.equals(cg.getClassName())) {
                            isClassAdvised = true;

                            // in static context
                            if (mg.isStatic()) {
                                insertPreAdvice(il, ih, cg, fieldName, factory, joinPointType);
                                insertPostAdvice(il, ih.getNext(), cg, fieldName, factory, joinPointType);

                                // skip the creation of the join point if we
                                // already have one
                                if (!getFieldJoinPoints.contains(fieldName)) {
                                    getFieldJoinPoints.add(fieldName);

                                    addStaticJoinPointField(cpg, cg, fieldName, joinPointType);

                                    if (noClInitMethod) {
                                        clInitMethod = createClInitMethodWithStaticJoinPointField(
                                                cpg, cg, fieldName, signature, factory,
                                                joinPointType, joinPointClass, uuid);
                                    }
                                    else {
                                        methods[clinitIndex] = createStaticJoinPointField(
                                                cpg, cg, methods[clinitIndex], fieldName, signature,
                                                factory, joinPointType, joinPointClass, uuid);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (ins instanceof PUTFIELD || ins instanceof PUTSTATIC) {
                    FieldInstruction pfIns = (FieldInstruction)ins;

                    String fieldName = pfIns.getName(cpg);
                    String signature = pfIns.getFieldType(cpg).toString() + " " + fieldName;
                    Type joinPointType = TransformationUtil.STATIC_FIELD_SET_JOIN_POINT_TYPE;
                    String joinPointClass = TransformationUtil.STATIC_FIELD_SET_JOIN_POINT_CLASS;

                    FieldMetaData fieldMetaData =
                            BcelMetaDataMaker.createFieldMetaData(pfIns, cpg);

                    String uuid = setFieldFilter(classMetaData, fieldMetaData);
                    if (uuid != null) {

                        String fieldClassName = pfIns.getClassName(cpg);
                        if (fieldClassName.equals(cg.getClassName())) {

                            // in static context
                            if (mg.isStatic()) {
                                isClassAdvised = true;
View Full Code Here

            InstructionList il = mg.getInstructionList();
            InstructionHandle ih = il.getStart();

            // get the current field instruction
            FieldInstruction currentGetFieldIns = null;

            // search for all GETFIELD and GETSTATIC instructions and
            // inserts the pre and post advices
            while (ih != null) {
                Instruction ins = ih.getInstruction();

                // handle the java.util.Collection classes
                if (ins instanceof GETFIELD || ins instanceof GETSTATIC) {
                    FieldInstruction checkMe = (FieldInstruction)ins;
                    // if the field is an added join point field => skip it
                    // needed if a field of type collection is both setField
                    // and getField advised
                    if (!checkMe.getFieldName(cpg).startsWith(TransformationUtil.JOIN_POINT_PREFIX)) {
                        currentGetFieldIns = checkMe;
                    }
                }
                if (ins instanceof INVOKEINTERFACE) {
                    final InvokeInstruction invokeIns = (InvokeInstruction)ins;

                    // do we have a collection?
                    if (invokeIns.getClassName(cpg).equals("java.util.Collection") ||
                            invokeIns.getClassName(cpg).equals("java.util.Enumeration") ||
                            invokeIns.getClassName(cpg).equals("java.util.Iterator") ||
                            invokeIns.getClassName(cpg).equals("java.util.List") ||
                            invokeIns.getClassName(cpg).equals("java.util.Map") ||
                            invokeIns.getClassName(cpg).equals("java.util.Set") ||
                            invokeIns.getClassName(cpg).equals("java.util.SortedMap") ||
                            invokeIns.getClassName(cpg).equals("java.util.SortedSet")) {

                        String methodName = invokeIns.getName(cpg);

                        // is the collection modified?
                        if (methodName.equals("add") ||
                                methodName.equals("addAll") ||
                                methodName.equals("set") ||
                                methodName.equals("remove") ||
                                methodName.equals("removeAll") ||
                                methodName.equals("retainAll") ||
                                methodName.equals("clear") ||
                                methodName.equals("put") ||
                                methodName.equals("putAll")) {

                            if (currentGetFieldIns == null) {
                                // is not a member field, continue
                                ih = ih.getNext();
                                continue;
                            }

                            final String fieldName = currentGetFieldIns.getName(cpg);
                            final String signature = currentGetFieldIns.getFieldType(cpg).
                                    toString() + " " + fieldName;
                            final Type joinPointType = TransformationUtil.MEMBER_FIELD_SET_JOIN_POINT_TYPE;

                            FieldMetaData fieldMetaData =
                                    BcelMetaDataMaker.createFieldMetaData(currentGetFieldIns, cpg);

                            String uuid = setFieldFilter(classMetaData, fieldMetaData);

                            if (uuid != null) {
                                final String fieldClassName = currentGetFieldIns.getClassName(cpg);

                                if (fieldClassName.equals(cg.getClassName())) {

                                    // is NOT in static context
                                    if (!mg.isStatic()) {
                                        isClassAdvised = true;

                                        insertPreAdvice(
                                                il, ih, cg, fieldName,
                                                factory, joinPointType);

                                        insertPostAdvice(
                                                il, ih.getNext(), cg,
                                                fieldName, factory, joinPointType);

                                        // store the join point field data
                                        JoinPointFieldData data = new JoinPointFieldData(
                                                fieldName, signature, joinPointType, uuid);

                                        if (!setFieldJoinPoints.contains(data)) {
                                            setFieldJoinPoints.add(data);
                                        }
                                    }
                                }
                                // set the current get field instruction to null
                                currentGetFieldIns = null;
                            }
                        }
                    }
                }
                // handle the getField instructions
                else if (ins instanceof GETFIELD || ins instanceof GETSTATIC) {
                    final FieldInstruction gfIns = (FieldInstruction)ins;

                    String fieldName = gfIns.getName(cpg);
                    String signature = gfIns.getFieldType(cpg).toString() + " " + fieldName;
                    Type joinPointType = TransformationUtil.MEMBER_FIELD_GET_JOIN_POINT_TYPE;

                    FieldMetaData fieldMetaData = BcelMetaDataMaker.createFieldMetaData(gfIns, cpg);

                    String uuid = getFieldFilter(classMetaData, fieldMetaData);
                    if (uuid != null) {

                        final String fieldClassName = gfIns.getClassName(cpg);
                        if (fieldClassName.equals(cg.getClassName())) {

                            // is NOT in static context
                            if (!mg.isStatic()) {
                                isClassAdvised = true;

                                insertPreAdvice(
                                        il, ih, cg, fieldName,
                                        factory, joinPointType);

                                insertPostAdvice(
                                        il, ih.getNext(), cg,
                                        fieldName, factory, joinPointType);

                                // store the join point field data
                                JoinPointFieldData data = new JoinPointFieldData(
                                        fieldName, signature, joinPointType, uuid);

                                if (!getFieldJoinPoints.contains(data)) {
                                    getFieldJoinPoints.add(data);
                                }
                            }
                        }
                    }
                }
                // handle the setField instructions
                else if (ins instanceof PUTFIELD || ins instanceof PUTSTATIC) {
                    final FieldInstruction pfIns = (FieldInstruction)ins;

                    String fieldName = pfIns.getName(cpg);
                    String signature = pfIns.getFieldType(cpg).toString() + " " + fieldName;
                    Type joinPointType = TransformationUtil.MEMBER_FIELD_SET_JOIN_POINT_TYPE;

                    FieldMetaData fieldMetaData =
                            BcelMetaDataMaker.createFieldMetaData(pfIns, cpg);

                    String uuid = setFieldFilter(classMetaData, fieldMetaData);
                    if (uuid != null) {

                        final String fieldClassName = pfIns.getClassName(cpg);
                        if (fieldClassName.equals(cg.getClassName())) {

                            // is NOT in static context
                            if (!mg.isStatic()) {
                                isClassAdvised = true;
View Full Code Here

TOP

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

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.