Java Code Examples for org.apache.bcel.Const#GETSTATIC
The following examples show how to use
org.apache.bcel.Const#GETSTATIC .
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: 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 2
Source File: StaticFieldLoadStreamFactory.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
@Override public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, RepositoryLookupFailureCallback lookupFailureCallback) { Instruction ins = location.getHandle().getInstruction(); if (ins.getOpcode() != Const.GETSTATIC) { return null; } GETSTATIC getstatic = (GETSTATIC) ins; if (!className.equals(getstatic.getClassName(cpg)) || !fieldName.equals(getstatic.getName(cpg)) || !fieldSig.equals(getstatic.getSignature(cpg))) { return null; } return new Stream(location, type.getClassName(), streamBaseClass).setIgnoreImplicitExceptions(true).setIsOpenOnCreation( true); }
Example 3
Source File: Hierarchy.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Look up the field referenced by given FieldInstruction, returning it as * an {@link XField XField} object. * * @param fins * the FieldInstruction * @param cpg * the ConstantPoolGen used by the class containing the * instruction * @return an XField object representing the field, or null if no such field * could be found */ public static @CheckForNull XField findXField(FieldInstruction fins, @Nonnull ConstantPoolGen cpg) { String className = fins.getClassName(cpg); String fieldName = fins.getFieldName(cpg); String fieldSig = fins.getSignature(cpg); boolean isStatic = (fins.getOpcode() == Const.GETSTATIC || fins.getOpcode() == Const.PUTSTATIC); XField xfield = findXField(className, fieldName, fieldSig, isStatic); short opcode = fins.getOpcode(); if (xfield != null && xfield.isResolved() && xfield.isStatic() == (opcode == Const.GETSTATIC || opcode == Const.PUTSTATIC)) { return xfield; } else { return null; } }
Example 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: FindNoSideEffectMethods.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void visit(Code obj) { uselessVoidCandidate = !classInit && !constructor && !getXMethod().isSynthetic() && Type.getReturnType(getMethodSig()) == Type.VOID; byte[] code = obj.getCode(); if (code.length == 4 && (code[0] & 0xFF) == Const.GETSTATIC && (code[3] & 0xFF) == Const.ARETURN) { getStaticMethods.add(getMethodDescriptor()); handleStatus(); return; } if (code.length <= 2 && !getXMethod().isStatic() && (getXMethod().isPublic() || getXMethod().isProtected()) && !getXMethod().isFinal() && (getXClass().isPublic() || getXClass().isProtected())) { for (byte[] stubMethod : STUB_METHODS) { if (Arrays.equals(stubMethod, code) && (getClassName().endsWith("Visitor") || getClassName().endsWith("Listener") || !hasOtherImplementations(getXMethod()))) { // stub method which can be extended: assume it can be extended with possible side-effect status = SideEffectStatus.SIDE_EFFECT; handleStatus(); return; } } } if (statusMap.containsKey(getMethodDescriptor())) { return; } finallyTargets = new HashSet<>(); for (CodeException ex : getCode().getExceptionTable()) { if (ex.getCatchType() == 0) { finallyTargets.add(ex.getHandlerPC()); } } finallyExceptionRegisters = new HashSet<>(); try { super.visit(obj); } catch (EarlyExitException e) { // Ignore } if (uselessVoidCandidate && code.length > 1 && (status == SideEffectStatus.UNSURE || status == SideEffectStatus.NO_SIDE_EFFECT)) { uselessVoidCandidates.add(getMethodDescriptor()); } handleStatus(); }
Example 14
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 15
Source File: InitializationChain.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { InvocationInfo prev = lastInvocation; lastInvocation = null; if (Const.CONSTRUCTOR_NAME.equals(getMethodName())) { if (seen == Const.GETSTATIC && getClassConstantOperand().equals(getClassName())) { staticFieldsReadInAnyConstructor.add(getXFieldOperand()); fieldsReadInThisConstructor.add(getXFieldOperand()); } return; } if (seen == Const.INVOKESPECIAL && Const.CONSTRUCTOR_NAME.equals(getNameConstantOperand()) && getClassConstantOperand().equals( getClassName())) { XMethod m = getXMethodOperand(); Set<XField> read = staticFieldsRead.get(m); if (constructorsInvokedInStaticInitializer.add(m) && read != null && !read.isEmpty()) { lastInvocation = new InvocationInfo(m, getPC()); invocationInfo.add(lastInvocation); } } if (seen == Const.PUTSTATIC && getClassConstantOperand().equals(getClassName())) { XField f = getXFieldOperand(); if (prev != null) { prev.field = f; } if (staticFieldsReadInAnyConstructor.contains(f) && !warningGiven.contains(f)) { for (InvocationInfo i : invocationInfo) { Set<XField> fields = staticFieldsRead.get(i.constructor); if (fields != null && fields.contains(f)) { warningGiven.add(f); BugInstance bug = new BugInstance(this, "SI_INSTANCE_BEFORE_FINALS_ASSIGNED", NORMAL_PRIORITY).addClassAndMethod(this); if (i.field != null) { bug.addField(i.field).describe(FieldAnnotation.STORED_ROLE); } bug.addMethod(i.constructor).describe(MethodAnnotation.METHOD_CONSTRUCTOR); bug.addReferencedField(this).describe(FieldAnnotation.VALUE_OF_ROLE).addSourceLine(this, i.pc); bugReporter.reportBug(bug); break; } } } } else if (seen == Const.PUTSTATIC || seen == Const.GETSTATIC || seen == Const.INVOKESTATIC || seen == Const.NEW) { if (getPC() + 6 < codeBytes.length) { requires.add(getDottedClassConstantOperand()); } } }
Example 16
Source File: GETSTATIC.java From commons-bcel with Apache License 2.0 | 4 votes |
public GETSTATIC(final int index) { super(Const.GETSTATIC, index); }