Java Code Examples for org.apache.bcel.Const#GETFIELD
The following examples show how to use
org.apache.bcel.Const#GETFIELD .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InstructionFactory.java From commons-bcel with Apache License 2.0 | 6 votes |
/** Create a field instruction. * * @param class_name name of the accessed class * @param name name of the referenced field * @param type type of field * @param kind how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC * @see Const */ public FieldInstruction createFieldAccess( final String class_name, final String name, final Type type, final short kind ) { int index; final String signature = type.getSignature(); index = cp.addFieldref(class_name, name, signature); switch (kind) { case Const.GETFIELD: return new GETFIELD(index); case Const.PUTFIELD: return new PUTFIELD(index); case Const.GETSTATIC: return new GETSTATIC(index); case Const.PUTSTATIC: return new PUTSTATIC(index); default: throw new IllegalArgumentException("Unknown getfield kind:" + kind); } }
Example 2
Source File: WrongMapIterator.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
public LoadedVariable seen(int opcode) { if (isRegisterLoad() && !isRegisterStore()) { return new LoadedVariable(LoadedVariableState.LOCAL, getRegisterOperand(), null); } switch (opcode) { case Const.GETSTATIC: return new LoadedVariable(LoadedVariableState.FIELD, 0, getFieldDescriptorOperand()); case Const.GETFIELD: if (lvState == LoadedVariableState.LOCAL && num == 0) { // Ignore fields from other classes return new LoadedVariable(LoadedVariableState.FIELD, 0, getFieldDescriptorOperand()); } return NONE; default: return NONE; } }
Example 3
Source File: ForwardTypeQualifierDataflowAnalysis.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private void registerInstructionSources() throws DataflowAnalysisException { for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) { Location location = i.next(); Instruction instruction = location.getHandle().getInstruction(); short opcode = instruction.getOpcode(); int produces = instruction.produceStack(cpg); if (instruction instanceof InvokeInstruction) { // Model return value registerReturnValueSource(location); } else if (opcode == Const.GETFIELD || opcode == Const.GETSTATIC) { // Model field loads registerFieldLoadSource(location); } else if (instruction instanceof LDC) { // Model constant values registerLDCValueSource(location); } else if (instruction instanceof LDC2_W) { // Model constant values registerLDC2ValueSource(location); } else if (instruction instanceof ConstantPushInstruction) { // Model constant values registerConstantPushSource(location); } else if (instruction instanceof ACONST_NULL) { // Model constant values registerPushNullSource(location); } else if ((produces == 1 || produces == 2) && !(instruction instanceof LocalVariableInstruction) && !(instruction instanceof CHECKCAST)) { // Model other sources registerOtherSource(location); } } }
Example 4
Source File: InnerClassAccessMap.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void handleInstruction(int opcode, int index) { switch (opcode) { case Const.GETFIELD: case Const.PUTFIELD: setField(getIndex(instructionList, index), false, opcode == Const.GETFIELD); break; case Const.GETSTATIC: case Const.PUTSTATIC: setField(getIndex(instructionList, index), true, opcode == Const.GETSTATIC); break; default: break; } }
Example 5
Source File: InstanceFieldLoadStreamFactory.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, RepositoryLookupFailureCallback lookupFailureCallback) { Instruction ins = location.getHandle().getInstruction(); if (ins.getOpcode() != Const.GETFIELD) { return null; } String fieldClass = type.getClassName(); try { if (fieldClass.startsWith("[")) { return null; } if (!Hierarchy.isSubtype(fieldClass, streamBaseClass)) { return null; } Stream stream = new Stream(location, fieldClass, streamBaseClass); stream.setIsOpenOnCreation(true); stream.setOpenLocation(location); if (bugPatternType != null) { stream.setInteresting(bugPatternType); } // System.out.println("Instance field stream at " + location); return stream; } catch (ClassNotFoundException e) { lookupFailureCallback.reportMissingClass(e); return null; } }
Example 6
Source File: NoteDirectlyRelevantTypeQualifiers.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void sawOpcode(int seen) { switch (seen) { case Const.INVOKEINTERFACE: case Const.INVOKEVIRTUAL: case Const.INVOKESTATIC: case Const.INVOKESPECIAL: // We don't need to look for method invocations // if Analysis.FIND_EFFECTIVE_RELEVANT_QUALIFIERS is enabled - // that will build an interprocedural call graph which // we'll use at a later point to find relevant qualifiers // stemming from called methods. if (!Analysis.FIND_EFFECTIVE_RELEVANT_QUALIFIERS) { XMethod m = getXMethodOperand(); if (m != null) { updateApplicableAnnotations(m); } } break; case Const.GETSTATIC: case Const.PUTSTATIC: case Const.GETFIELD: case Const.PUTFIELD: { XField f = getXFieldOperand(); if (f != null) { Collection<TypeQualifierAnnotation> annotations = TypeQualifierApplications.getApplicableApplications(f); Analysis.addKnownTypeQualifiers(applicableApplications, annotations); } break; } default: break; } }
Example 7
Source File: FieldSetAnalysis.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private void handleInstruction(InstructionHandle handle, BasicBlock basicBlock, FieldSet fact) { Instruction ins = handle.getInstruction(); short opcode = ins.getOpcode(); XField field; switch (opcode) { case Const.GETFIELD: case Const.GETSTATIC: field = lookupField(handle, (FieldInstruction) ins); if (field != null) { sawLoad(fact, field); } break; case Const.PUTFIELD: case Const.PUTSTATIC: field = lookupField(handle, (FieldInstruction) ins); if (field != null) { sawStore(fact, field); } break; case Const.INVOKEINTERFACE: case Const.INVOKESPECIAL: case Const.INVOKESTATIC: case Const.INVOKEVIRTUAL: // Assume that the called method assigns loads and stores all // possible fields fact.setBottom(); break; default: break; } }
Example 8
Source File: MutableLock.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void sawOpcode(int seen) { switch (seen) { case Const.ALOAD_0: thisOnTOS = true; return; case Const.MONITOREXIT: setFields.clear(); break; case Const.PUTFIELD: if (getClassConstantOperand().equals(getClassName())) { setFields.add(getNameConstantOperand()); } break; case Const.GETFIELD: if (thisOnTOS && getClassConstantOperand().equals(getClassName()) && setFields.contains(getNameConstantOperand()) && asUnsignedByte(codeBytes[getPC() + 3]) == Const.DUP && asUnsignedByte(codeBytes[getPC() + 5]) == Const.MONITORENTER && !finalFields.contains(getNameConstantOperand())) { bugReporter.reportBug(new BugInstance(this, "ML_SYNC_ON_UPDATED_FIELD", NORMAL_PRIORITY).addClassAndMethod(this) .addReferencedField(this).addSourceLine(this, getPC() + 5)); } break; default: break; } thisOnTOS = false; }
Example 9
Source File: SynchronizeAndNullCheckField.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { // System.out.println(getPC() + " " + Const.getOpcodeName(seen) + " " + // currState); switch (currState) { case 0: if (seen == Const.GETFIELD || seen == Const.GETSTATIC) { syncField = FieldAnnotation.fromReferencedField(this); currState = 1; } break; case 1: if (seen == Const.DUP) { currState = 2; } else { currState = 0; } break; case 2: if (seen == Const.ASTORE || seen == Const.ASTORE_0 || seen == Const.ASTORE_1 || seen == Const.ASTORE_2 || seen == Const.ASTORE_3) { currState = 3; } else { currState = 0; } break; case 3: if (seen == Const.MONITORENTER) { currState = 4; } else { currState = 0; } break; case 4: if (seen == Const.GETFIELD || seen == Const.GETSTATIC) { gottenField = FieldAnnotation.fromReferencedField(this); currState = 5; } else { currState = 0; } break; case 5: if ((seen == Const.IFNONNULL || seen == Const.IFNULL) && gottenField.equals(syncField)) { BugInstance bug = new BugInstance(this, "NP_SYNC_AND_NULL_CHECK_FIELD", NORMAL_PRIORITY).addClass(this) .addMethod(this).addField(syncField).addSourceLine(this); bugReporter.reportBug(bug); } else { currState = 0; } break; default: currState = 0; } }
Example 10
Source File: GETFIELD.java From commons-bcel with Apache License 2.0 | 4 votes |
public GETFIELD(final int index) { super(Const.GETFIELD, index); }
Example 11
Source File: FindNonShortCircuit.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
private void scanForDanger(int seen) { switch (seen) { case Const.AALOAD: case Const.BALOAD: case Const.SALOAD: case Const.CALOAD: case Const.IALOAD: case Const.LALOAD: case Const.FALOAD: case Const.DALOAD: sawArrayDanger = true; sawDanger = true; break; case Const.INVOKEVIRTUAL: if ("length".equals(getNameConstantOperand()) && "java/lang/String".equals(getClassConstantOperand())) { break; } sawDanger = true; sawMethodCall = true; break; case Const.INVOKEINTERFACE: case Const.INVOKESPECIAL: case Const.INVOKESTATIC: sawDanger = true; sawMethodCall = true; break; case Const.IDIV: case Const.IREM: case Const.LDIV: case Const.LREM: sawDanger = true; break; case Const.ARRAYLENGTH: case Const.GETFIELD: // null pointer detector will handle these break; default: break; } }
Example 12
Source File: FindInconsistentSync2.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
/** * Determine whether or not the the given method is a getter method. I.e., * if it just returns the value of an instance field. * * @param classContext * the ClassContext for the class containing the method * @param method * the method */ public static boolean isGetterMethod(ClassContext classContext, Method method) { MethodGen methodGen = classContext.getMethodGen(method); if (methodGen == null) { return false; } InstructionList il = methodGen.getInstructionList(); // System.out.println("Checking getter method: " + method.getName()); if (il.getLength() > 60) { return false; } int count = 0; for (InstructionHandle ih : il) { switch (ih.getInstruction().getOpcode()) { case Const.GETFIELD: count++; if (count > 1) { return false; } break; case Const.PUTFIELD: case Const.BALOAD: case Const.CALOAD: case Const.DALOAD: case Const.FALOAD: case Const.IALOAD: case Const.LALOAD: case Const.SALOAD: case Const.AALOAD: case Const.BASTORE: case Const.CASTORE: case Const.DASTORE: case Const.FASTORE: case Const.IASTORE: case Const.LASTORE: case Const.SASTORE: case Const.AASTORE: case Const.PUTSTATIC: return false; case Const.INVOKESTATIC: case Const.INVOKEVIRTUAL: case Const.INVOKEINTERFACE: case Const.INVOKESPECIAL: case Const.GETSTATIC: // no-op } } // System.out.println("Found getter method: " + method.getName()); return true; }
Example 13
Source File: FindSpinLoop.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { // System.out.println("PC: " + PC + ", stage: " + stage1); switch (seen) { case Const.ALOAD_0: case Const.ALOAD_1: case Const.ALOAD_2: case Const.ALOAD_3: case Const.ALOAD: if (DEBUG) { System.out.println(" ALOAD at PC " + getPC()); } start = getPC(); stage = 1; break; case Const.GETSTATIC: if (DEBUG) { System.out.println(" getfield in stage " + stage); } lastFieldSeen = FieldAnnotation.fromReferencedField(this); start = getPC(); stage = 2; break; case Const.GETFIELD: if (DEBUG) { System.out.println(" getfield in stage " + stage); } lastFieldSeen = FieldAnnotation.fromReferencedField(this); if (stage == 1 || stage == 2) { stage = 2; } else { stage = 0; } break; case Const.GOTO: case Const.IFNE: case Const.IFEQ: case Const.IFNULL: case Const.IFNONNULL: if (DEBUG) { System.out.println(" conditional branch in stage " + stage + " to " + getBranchTarget()); } if (stage == 2 && getBranchTarget() == start) { bugReporter.reportBug(new BugInstance(this, "SP_SPIN_ON_FIELD", NORMAL_PRIORITY).addClassAndMethod(this) .addReferencedField(lastFieldSeen).addSourceLine(this, start)); stage = 0; } else if (getBranchTarget() < getPC()) { stage = 0; } break; default: stage = 0; break; } }
Example 14
Source File: Noise.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { int priority; switch (seen) { case Const.INVOKEINTERFACE: case Const.INVOKEVIRTUAL: case Const.INVOKESPECIAL: case Const.INVOKESTATIC: hq.pushHash(getClassConstantOperand()); if (getNameConstantOperand().indexOf('$') == -1) { hq.pushHash(getNameConstantOperand()); } hq.pushHash(getSigConstantOperand()); priority = hq.getPriority(); if (priority <= Priorities.LOW_PRIORITY) { accumulator.accumulateBug(new BugInstance(this, "NOISE_METHOD_CALL", priority).addClassAndMethod(this) .addCalledMethod(this), this); } break; case Const.GETFIELD: case Const.PUTFIELD: case Const.GETSTATIC: case Const.PUTSTATIC: hq.pushHash(getClassConstantOperand()); if (getNameConstantOperand().indexOf('$') == -1) { hq.pushHash(getNameConstantOperand()); } hq.pushHash(getSigConstantOperand()); priority = hq.getPriority(); if (priority <= Priorities.LOW_PRIORITY) { accumulator.accumulateBug(new BugInstance(this, "NOISE_FIELD_REFERENCE", priority).addClassAndMethod(this) .addReferencedField(this), this); } break; case Const.CHECKCAST: case Const.INSTANCEOF: case Const.NEW: hq.pushHash(getClassConstantOperand()); break; case Const.IFEQ: case Const.IFNE: case Const.IFNONNULL: case Const.IFNULL: case Const.IF_ICMPEQ: case Const.IF_ICMPNE: case Const.IF_ICMPLE: case Const.IF_ICMPGE: case Const.IF_ICMPGT: case Const.IF_ICMPLT: case Const.IF_ACMPEQ: case Const.IF_ACMPNE: case Const.RETURN: case Const.ARETURN: case Const.IRETURN: case Const.MONITORENTER: case Const.MONITOREXIT: case Const.IINC: case Const.NEWARRAY: case Const.TABLESWITCH: case Const.LOOKUPSWITCH: case Const.LCMP: case Const.INEG: case Const.IADD: case Const.IMUL: case Const.ISUB: case Const.IDIV: case Const.IREM: case Const.IXOR: case Const.ISHL: case Const.ISHR: case Const.IUSHR: case Const.IAND: case Const.IOR: case Const.LAND: case Const.LOR: case Const.LADD: case Const.LMUL: case Const.LSUB: case Const.LDIV: case Const.LSHL: case Const.LSHR: case Const.LUSHR: case Const.AALOAD: case Const.AASTORE: case Const.IALOAD: case Const.IASTORE: case Const.BALOAD: case Const.BASTORE: hq.push(seen); priority = hq.getPriority(); if (priority <= Priorities.LOW_PRIORITY) { accumulator.accumulateBug( new BugInstance(this, "NOISE_OPERATION", priority).addClassAndMethod(this).addString(Const.getOpcodeName(seen)), this); } break; default: break; } }
Example 15
Source File: SynchronizingOnContentsOfFieldToProtectField.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { // System.out.println(state + " " + getPC() + " " + Const.getOpcodeName(seen)); if (countDown == 2 && seen == Const.GOTO) { CodeException tryBlock = getSurroundingTryBlock(getPC()); if (tryBlock != null && tryBlock.getEndPC() == getPC()) { pendingBug.lowerPriority(); } } if (countDown > 0) { countDown--; if (countDown == 0) { if (seen == Const.MONITOREXIT) { pendingBug.lowerPriority(); } bugReporter.reportBug(pendingBug); pendingBug = null; } } if (seen == Const.PUTFIELD) { if (syncField != null && getPrevOpcode(1) != Const.ALOAD_0 && syncField.equals(getXFieldOperand())) { OpcodeStack.Item value = stack.getStackItem(0); int priority = Priorities.HIGH_PRIORITY; if (value.isNull()) { priority = Priorities.NORMAL_PRIORITY; } pendingBug = new BugInstance(this, "ML_SYNC_ON_FIELD_TO_GUARD_CHANGING_THAT_FIELD", priority) .addClassAndMethod(this).addField(syncField).addSourceLine(this); countDown = 2; } } if (seen == Const.MONITOREXIT) { pendingBug = null; countDown = 0; } if (seen == Const.MONITORENTER) { syncField = null; } switch (state) { case 0: if (seen == Const.ALOAD_0) { state = 1; } break; case 1: if (seen == Const.GETFIELD) { state = 2; field = getXFieldOperand(); } else { state = 0; } break; case 2: if (seen == Const.DUP) { state = 3; } else { state = 0; } break; case 3: if (isRegisterStore()) { state = 4; } else { state = 0; } break; case 4: if (seen == Const.MONITORENTER) { state = 0; syncField = field; } else { state = 0; } break; default: break; } }
Example 16
Source File: SuspiciousThreadInterrupted.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { if (state == SEEN_POSSIBLE_THREAD) { if (seen == Const.POP) { state = SEEN_UNKNOWNCONTEXT_POP; return; } else { state = SEEN_NOTHING; } } switch (state) { case SEEN_NOTHING: if ((seen == Const.INVOKESTATIC) && "java/lang/Thread".equals(getClassConstantOperand()) && "currentThread".equals(getNameConstantOperand()) && "()Ljava/lang/Thread;".equals(getSigConstantOperand())) { state = SEEN_CURRENTTHREAD; } else if ((seen == Const.INVOKESTATIC || seen == Const.INVOKEINTERFACE || seen == Const.INVOKEVIRTUAL || seen == Const.INVOKESPECIAL) && getSigConstantOperand().endsWith("Ljava/lang/Thread;")) { state = SEEN_POSSIBLE_THREAD; } else if (seen == Const.ALOAD) { if (localsWithCurrentThreadValue.get(getRegisterOperand())) { state = SEEN_CURRENTTHREAD; } else { state = SEEN_POSSIBLE_THREAD; } } else if ((seen >= Const.ALOAD_0) && (seen <= Const.ALOAD_3)) { if (localsWithCurrentThreadValue.get(seen - Const.ALOAD_0)) { state = SEEN_CURRENTTHREAD; } else { state = SEEN_POSSIBLE_THREAD; } } else if ((seen == Const.GETFIELD || seen == Const.GETSTATIC) && "Ljava/lang/Thread;".equals(getSigConstantOperand())) { state = SEEN_POSSIBLE_THREAD; } break; case SEEN_CURRENTTHREAD: if (seen == Const.POP) { state = SEEN_POP_AFTER_CURRENTTHREAD; } else if (seen == Const.ASTORE) { localsWithCurrentThreadValue.set(getRegisterOperand()); state = SEEN_NOTHING; } else if ((seen >= Const.ASTORE_0) && (seen <= Const.ASTORE_3)) { localsWithCurrentThreadValue.set(seen - Const.ASTORE_0); state = SEEN_NOTHING; } else { state = SEEN_NOTHING; } break; default: if ((seen == Const.INVOKESTATIC) && "java/lang/Thread".equals(getClassConstantOperand()) && "interrupted".equals(getNameConstantOperand()) && "()Z".equals(getSigConstantOperand())) { if (state == SEEN_POP_AFTER_CURRENTTHREAD) { bugReporter.reportBug(new BugInstance(this, "STI_INTERRUPTED_ON_CURRENTTHREAD", LOW_PRIORITY) .addClassAndMethod(this).addSourceLine(this)); } else if (state == SEEN_UNKNOWNCONTEXT_POP) { bugReporter.reportBug(new BugInstance(this, "STI_INTERRUPTED_ON_UNKNOWNTHREAD", NORMAL_PRIORITY) .addClassAndMethod(this).addSourceLine(this)); } } state = SEEN_NOTHING; break; } }
Example 17
Source File: FindUninitializedGet.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { if (!inConstructor) { return; } if (uninitializedFieldReadAndCheckedForNonnull != null) { if (seen == Const.NEW && getClassConstantOperand().endsWith("Exception")) { uninitializedFieldReadAndCheckedForNonnull.raisePriority(); } uninitializedFieldReadAndCheckedForNonnull = null; } if (seen == Const.ALOAD_0) { thisOnTOS = true; return; } if (seen == Const.PUTFIELD && getClassConstantOperand().equals(getClassName())) { initializedFields.add(FieldAnnotation.fromReferencedField(this)); } else if (thisOnTOS && seen == Const.GETFIELD && getClassConstantOperand().equals(getClassName())) { UnreadFieldsData unreadFields = AnalysisContext.currentAnalysisContext().getUnreadFieldsData(); XField xField = XFactory.createReferencedXField(this); FieldAnnotation f = FieldAnnotation.fromReferencedField(this); int nextOpcode = 0xff & codeBytes[getPC() + 3]; if (nextOpcode != Const.POP && !initializedFields.contains(f) && declaredFields.contains(f) && !containerFields.contains(f) && !unreadFields.isContainerField(xField)) { // System.out.println("Next opcode: " + // Const.getOpcodeName(nextOpcode)); LocalVariableAnnotation possibleTarget = LocalVariableAnnotation.findMatchingIgnoredParameter(getClassContext(), getMethod(), getNameConstantOperand(), xField.getSignature()); if (possibleTarget == null) { possibleTarget = LocalVariableAnnotation.findUniqueBestMatchingParameter(getClassContext(), getMethod(), getNameConstantOperand(), getSigConstantOperand()); } int priority = unreadFields.getReadFields().contains(xField) ? NORMAL_PRIORITY : LOW_PRIORITY; boolean priorityLoweredBecauseOfIfNonnullTest = false; if (possibleTarget != null) { priority--; } else { FieldSummary fieldSummary = AnalysisContext.currentAnalysisContext().getFieldSummary(); if (fieldSummary.callsOverriddenMethodsFromSuperConstructor(getClassDescriptor())) { priority++; } else if (nextOpcode == Const.IFNONNULL) { priority++; priorityLoweredBecauseOfIfNonnullTest = true; } } BugInstance bug = new BugInstance(this, "UR_UNINIT_READ", priority).addClassAndMethod(this).addField(f) .addOptionalAnnotation(possibleTarget).addSourceLine(this); pendingBugs.add(bug); if (priorityLoweredBecauseOfIfNonnullTest) { uninitializedFieldReadAndCheckedForNonnull = bug; } initializedFields.add(f); } } else if ((seen == Const.INVOKESPECIAL && !(Const.CONSTRUCTOR_NAME.equals(getNameConstantOperand()) && !getClassConstantOperand().equals( getClassName()))) || (seen == Const.INVOKESTATIC && "doPrivileged".equals(getNameConstantOperand()) && "java/security/AccessController".equals( getClassConstantOperand())) || (seen == Const.INVOKEVIRTUAL && getClassConstantOperand().equals(getClassName())) || (seen == Const.INVOKEVIRTUAL && "start".equals(getNameConstantOperand()))) { inConstructor = false; } thisOnTOS = false; }