org.apache.bcel.generic.PUTSTATIC Java Examples
The following examples show how to use
org.apache.bcel.generic.PUTSTATIC.
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: ValueNumberFrameModelingVisitor.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void visitPUTSTATIC(PUTSTATIC obj) { if (doForwardSubstitution()) { XField xfield = Hierarchy.findXField(obj, getCPG()); if (xfield != null) { storeStaticField(xfield, obj, false); return; } } handleNormalInstruction(obj); }
Example #2
Source File: FieldAnnotation.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Is the instruction a write of a field? * * @param ins * the Instruction to check * @param cpg * ConstantPoolGen of the method containing the instruction * @return the Field if instruction is a write of a field, null otherwise */ public static FieldAnnotation isWrite(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof PUTFIELD || ins instanceof PUTSTATIC) { FieldInstruction fins = (FieldInstruction) ins; String className = fins.getClassName(cpg); return new FieldAnnotation(className, fins.getName(cpg), fins.getSignature(cpg), fins instanceof PUTSTATIC); } else { return null; } }
Example #3
Source File: PUTSTATICReference.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * @param aInstruction * @param aPoolGen */ public PUTSTATICReference( PUTSTATIC aInstruction, ConstantPoolGen aPoolGen) { super(aInstruction, aPoolGen); }
Example #4
Source File: PUTSTATICReference.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
/** * @param aInstruction * @param aPoolGen */ public PUTSTATICReference( PUTSTATIC aInstruction, ConstantPoolGen aPoolGen) { super(aInstruction, aPoolGen); }
Example #5
Source File: ResourceValueFrameModelingVisitor.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void visitPUTSTATIC(PUTSTATIC putstatic) { handleFieldStore(putstatic); }
Example #6
Source File: UnconditionalValueDerefAnalysis.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock, UnconditionalValueDerefSet fact) throws DataflowAnalysisException { Instruction instruction = handle.getInstruction(); if (fact.isTop()) { return; } Location location = new Location(handle, basicBlock); // If this is a call to an assertion method, // change the dataflow value to be TOP. // We don't want to report future derefs that would // be guaranteed only if the assertion methods // returns normally. // TODO: at some point, evaluate whether we should revisit this if (isAssertion(handle) // || handle.getInstruction() instanceof ATHROW ) { if (DEBUG) { System.out.println("MAKING BOTTOM0 AT: " + location); } fact.clear(); return; } // Get value number frame ValueNumberFrame vnaFrame = vnaDataflow.getFactAtLocation(location); if (!vnaFrame.isValid()) { if (DEBUG) { System.out.println("MAKING TOP1 AT: " + location); } // Probably dead code. // Assume this location can't be reached. makeFactTop(fact); return; } if (isNullCheck(handle, methodGen.getConstantPool())) { handleNullCheck(location, vnaFrame, fact); } // Check for calls to a method that unconditionally dereferences // a parameter. Mark any such arguments as derefs. if (CHECK_CALLS && instruction instanceof InvokeInstruction) { checkUnconditionalDerefDatabase(location, vnaFrame, fact); } // If this is a method call instruction, // check to see if any of the parameters are @NonNull, // and treat them as dereferences. if (CHECK_ANNOTATIONS && instruction instanceof InvokeInstruction) { checkNonNullParams(location, vnaFrame, fact); } if (CHECK_ANNOTATIONS && instruction instanceof ARETURN) { XMethod thisMethod = XFactory.createXMethod(methodGen); checkNonNullReturnValue(thisMethod, location, vnaFrame, fact); } if (CHECK_ANNOTATIONS && (instruction instanceof PUTFIELD || instruction instanceof PUTSTATIC)) { checkNonNullPutField(location, vnaFrame, fact); } // Check to see if an instance value is dereferenced here checkInstance(location, vnaFrame, fact); /* if (false) { fact.cleanDerefSet(location, vnaFrame); }*/ if (DEBUG && fact.isTop()) { System.out.println("MAKING TOP2 At: " + location); } }
Example #7
Source File: BetterCFGBuilder2.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
/** * Return whether or not the given instruction can throw exceptions. * * @param handle * the instruction * @return true if the instruction can throw an exception, false otherwise * @throws CFGBuilderException */ private boolean isPEI(InstructionHandle handle) throws CFGBuilderException { Instruction ins = handle.getInstruction(); if (!(ins instanceof ExceptionThrower)) { return false; } if (ins instanceof NEW) { return false; } // if (ins instanceof ATHROW) return false; if (ins instanceof GETSTATIC) { return false; } if (ins instanceof PUTSTATIC) { return false; } if (ins instanceof ReturnInstruction) { return false; } if (ins instanceof INSTANCEOF) { return false; } if (ins instanceof MONITOREXIT) { return false; } if (ins instanceof LDC) { return false; } if (ins instanceof GETFIELD && !methodGen.isStatic()) { // Assume that GETFIELD on this object is not PEI return !isSafeFieldSource(handle.getPrev()); } if (ins instanceof PUTFIELD && !methodGen.isStatic()) { // Assume that PUTFIELD on this object is not PEI int depth = ins.consumeStack(cpg); for (InstructionHandle prev = handle.getPrev(); prev != null; prev = prev.getPrev()) { Instruction prevInst = prev.getInstruction(); if (prevInst instanceof BranchInstruction) { if (prevInst instanceof GotoInstruction) { // Currently we support only jumps to the PUTFIELD itself // This will cover simple cases like this.a = flag ? foo : bar if (((BranchInstruction) prevInst).getTarget() == handle) { depth = ins.consumeStack(cpg); } else { return true; } } else if (!(prevInst instanceof IfInstruction)) { // As IF instructions may fall through then the stack depth remains unchanged // Actually we should not go here for normal Java bytecode: switch or jsr should not appear in this context return true; } } depth = depth - prevInst.produceStack(cpg) + prevInst.consumeStack(cpg); if (depth < 1) { throw new CFGBuilderException("Invalid stack at " + prev + " when checking " + handle); } if (depth == 1) { InstructionHandle prevPrev = prev.getPrev(); if (prevPrev != null && prevPrev.getInstruction() instanceof BranchInstruction) { continue; } return !isSafeFieldSource(prevPrev); } } } return true; }
Example #8
Source File: ReferenceVisitor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** @see org.apache.bcel.generic.Visitor */ public void visitPUTSTATIC(PUTSTATIC aPUTSTATIC) { addFieldReference( new PUTSTATICReference(aPUTSTATIC, mCurrentPoolGen)); }
Example #9
Source File: ReferenceVisitor.java From contribution with GNU Lesser General Public License v2.1 | 4 votes |
/** @see org.apache.bcel.generic.Visitor */ public void visitPUTSTATIC(PUTSTATIC aPUTSTATIC) { addFieldReference( new PUTSTATICReference(aPUTSTATIC, mCurrentPoolGen)); }
Example #10
Source File: Pass3aVerifier.java From commons-bcel with Apache License 2.0 | 4 votes |
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override public void visitPUTSTATIC(final PUTSTATIC o) { try { final String field_name = o.getFieldName(constantPoolGen); final JavaClass jc = Repository.lookupClass(getObjectType(o).getClassName()); final Field[] fields = jc.getFields(); Field f = null; for (final Field field : fields) { if (field.getName().equals(field_name)) { f = field; break; } } if (f == null) { throw new AssertionViolatedException("Field '" + field_name + "' not found in " + jc.getClassName()); } if (f.isFinal()) { if (!(myOwner.getClassName().equals(getObjectType(o).getClassName()))) { constraintViolated(o, "Referenced field '"+f+"' is final and must therefore be declared in the current class '"+ myOwner.getClassName()+"' which is not the case: it is declared in '"+o.getReferenceType(constantPoolGen)+"'."); } } if (! (f.isStatic())) { constraintViolated(o, "Referenced field '"+f+"' is not static which it should be."); } final String meth_name = Repository.lookupClass(myOwner.getClassName()).getMethods()[methodNo].getName(); // If it's an interface, it can be set only in <clinit>. if ((!(jc.isClass())) && (!(meth_name.equals(Const.STATIC_INITIALIZER_NAME)))) { constraintViolated(o, "Interface field '"+f+"' must be set in a '"+Const.STATIC_INITIALIZER_NAME+"' method."); } } catch (final ClassNotFoundException e) { // FIXME: maybe not the best way to handle this throw new AssertionViolatedException("Missing class: " + e, e); } }