constValue = ((ConstantFloat) c).getBytes(); } else if (c instanceof ConstantLong) { constValue = ((ConstantLong) c).getBytes(); } else { state = SEEN_NOTHING;
private void pushByConstant(DismantleBytecode dbc, Constant c) { if (c instanceof ConstantClass) { push(new Item("Ljava/lang/Class;", ((ConstantClass) c).getConstantValue(dbc.getConstantPool()))); } else if (c instanceof ConstantInteger) { push(new Item("I", Integer.valueOf(((ConstantInteger) c).getBytes()))); } else if (c instanceof ConstantString) { int s = ((ConstantString) c).getStringIndex(); push(new Item("Ljava/lang/String;", getStringFromIndex(dbc, s))); } else if (c instanceof ConstantFloat) { push(new Item("F", Float.valueOf(((ConstantFloat) c).getBytes()))); } else if (c instanceof ConstantDouble) { push(new Item("D", Double.valueOf(((ConstantDouble) c).getBytes()))); } else if (c instanceof ConstantLong) { push(new Item("J", Long.valueOf(((ConstantLong) c).getBytes()))); } else { throw new UnsupportedOperationException("StaticConstant type not expected"); } }
@Override public void visit(Field field) { ConstantValue value = field.getConstantValue(); if (value == null) { return; } Constant c = getConstantPool().getConstant(value.getConstantValueIndex()); if (testingEnabled && c instanceof ConstantLong && ((ConstantLong)c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT) { bugReporter.reportBug( new BugInstance(this, "TESTING", HIGH_PRIORITY).addClass(this).addField(this) .addString("Did you mean MICROS_PER_DAY") .addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT) .describe(IntAnnotation.INT_VALUE)); } } @Override
intConstant = ((ConstantInteger) constantRefOperand).getBytes(); } else if (constantRefOperand instanceof ConstantLong) { longConstant = ((ConstantLong) constantRefOperand).getBytes(); } else if (constantRefOperand instanceof ConstantFloat) { floatConstant = ((ConstantFloat) constantRefOperand).getBytes();
Constant c = getConstantRefOperand(); if (testingEnabled && (c instanceof ConstantInteger && ((ConstantInteger) c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT || c instanceof ConstantLong && ((ConstantLong) c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT)) { BugInstance bug = new BugInstance(this, "TESTING", HIGH_PRIORITY).addClassAndMethod(this) .addString("Did you mean MICROS_PER_DAY").addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT) || c instanceof ConstantLong && ((ConstantLong) c).getBytes() == Long.MIN_VALUE)) { sawLoadOfMinValue = true; pendingAbsoluteValueBug = null;
/** * Initialize from another object. */ public ConstantLong(ConstantLong c) { this(c.getBytes()); } /**
/** * Initialize from another object. */ public ConstantLong(final ConstantLong c) { this(c.getBytes()); }
/** * Look for ConstantLong in ConstantPool. * * @param n Long number to look for * @return index on success, -1 otherwise */ public int lookupLong(long n) { for(int i=1; i < index; i++) { if(constants[i] instanceof ConstantLong) { ConstantLong c = (ConstantLong)constants[i]; if(c.getBytes() == n) return i; } } return -1; }
/** * Look for ConstantLong in ConstantPool. * * @param n Long number to look for * @return index on success, -1 otherwise */ public int lookupLong( final long n ) { for (int i = 1; i < index; i++) { if (constants[i] instanceof ConstantLong) { final ConstantLong c = (ConstantLong) constants[i]; if (c.getBytes() == n) { return i; } } } return -1; }
public Number getValue(ConstantPoolGen cpg) { org.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(index); switch(c.getTag()) { case org.apache.bcel.Constants.CONSTANT_Long: return new Long(((org.apache.bcel.classfile.ConstantLong)c).getBytes()); case org.apache.bcel.Constants.CONSTANT_Double: return new Double(((org.apache.bcel.classfile.ConstantDouble)c).getBytes()); default: // Never reached throw new RuntimeException("Unknown or invalid constant type at " + index); } }
public long getValueLong() { if (super.getType() != PRIMITIVE_LONG) { throw new RuntimeException( "Dont call getValueLong() on a non LONG ElementValue"); } final ConstantLong j = (ConstantLong) super.getConstantPool().getConstant(getIndex()); return j.getBytes(); }
public Number getValue( final ConstantPoolGen cpg ) { final org.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(super.getIndex()); switch (c.getTag()) { case org.apache.bcel.Const.CONSTANT_Long: return Long.valueOf(((org.apache.bcel.classfile.ConstantLong) c).getBytes()); case org.apache.bcel.Const.CONSTANT_Double: return new Double(((org.apache.bcel.classfile.ConstantDouble) c).getBytes()); default: // Never reached throw new RuntimeException("Unknown or invalid constant type at " + super.getIndex()); } }
constValue = ((ConstantFloat) c).getBytes(); } else if (c instanceof ConstantLong) { constValue = ((ConstantLong) c).getBytes(); } else { state = SEEN_NOTHING;
buf = String.valueOf(((ConstantLong) c).getBytes()); break; case Const.CONSTANT_Float:
private void pushByConstant(DismantleBytecode dbc, Constant c) { if (c instanceof ConstantClass) { push(new Item("Ljava/lang/Class;", ((ConstantClass) c).getConstantValue(dbc.getConstantPool()))); } else if (c instanceof ConstantInteger) { push(new Item("I", Integer.valueOf(((ConstantInteger) c).getBytes()))); } else if (c instanceof ConstantString) { int s = ((ConstantString) c).getStringIndex(); push(new Item("Ljava/lang/String;", getStringFromIndex(dbc, s))); } else if (c instanceof ConstantFloat) { push(new Item("F", Float.valueOf(((ConstantFloat) c).getBytes()))); } else if (c instanceof ConstantDouble) { push(new Item("D", Double.valueOf(((ConstantDouble) c).getBytes()))); } else if (c instanceof ConstantLong) { push(new Item("J", Long.valueOf(((ConstantLong) c).getBytes()))); } else { throw new UnsupportedOperationException("StaticConstant type not expected"); } }
/** * @return String representation of constant value. */ public final String toString() { Constant c = constant_pool.getConstant(constantvalue_index); String buf; int i; // Print constant to string depending on its type switch(c.getTag()) { case Constants.CONSTANT_Long: buf = "" + ((ConstantLong)c).getBytes(); break; case Constants.CONSTANT_Float: buf = "" + ((ConstantFloat)c).getBytes(); break; case Constants.CONSTANT_Double: buf = "" + ((ConstantDouble)c).getBytes(); break; case Constants.CONSTANT_Integer: buf = "" + ((ConstantInteger)c).getBytes(); break; case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); c = constant_pool.getConstant(i, Constants.CONSTANT_Utf8); buf = "\"" + Utility.convertString(((ConstantUtf8)c).getBytes()) + "\""; break; default: throw new IllegalStateException("Type of ConstValue invalid: " + c); } return buf; }
case PRIMITIVE_LONG: final ConstantLong j = (ConstantLong) getConstantPool().getConstant(idx); return Long.toString(j.getBytes()); case PRIMITIVE_DOUBLE: final ConstantDouble d = (ConstantDouble) getConstantPool().getConstant(idx);
@Override public void visit(Field field) { ConstantValue value = field.getConstantValue(); if (value == null) { return; } Constant c = getConstantPool().getConstant(value.getConstantValueIndex()); if (testingEnabled && c instanceof ConstantLong && ((ConstantLong)c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT) { bugReporter.reportBug( new BugInstance(this, "TESTING", HIGH_PRIORITY).addClass(this).addField(this) .addString("Did you mean MICROS_PER_DAY") .addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT) .describe(IntAnnotation.INT_VALUE)); } } @Override
break; case Constants.CONSTANT_Long: str= "" + ((ConstantLong) c).getBytes(); break; case Constants.CONSTANT_Integer:
case Constants.CONSTANT_Double: str = "" + ((ConstantDouble)c).getBytes(); break; case Constants.CONSTANT_Float: str = "" + ((ConstantFloat)c).getBytes(); break; case Constants.CONSTANT_Long: str = "" + ((ConstantLong)c).getBytes(); break; case Constants.CONSTANT_Integer: str = "" + ((ConstantInteger)c).getBytes(); break;