private boolean hasInterestingConstant(ConstantPool cp) { for(Constant constant : cp.getConstantPool()) { if(constant instanceof ConstantFloat) { float val = ((ConstantFloat)constant).getBytes(); if(isInteresting(val, val)) { return true; } } if(constant instanceof ConstantDouble) { double val = ((ConstantDouble)constant).getBytes(); if(isInteresting(val, val)) { return true; } } } return false; }
break; case org.apache.bcel.Const.CONSTANT_Double: str = ((ConstantDouble) c).toString(); break; case org.apache.bcel.Const.CONSTANT_Float:
/** * Add a new double constant to the ConstantPool, if it is not already in there. * * @param n Double number to add * @return index of entry */ public int addDouble(double n) { int ret; if((ret = lookupDouble(n)) != -1) return ret; // Already in CP adjustSize(); ret = index; constants[index] = new ConstantDouble(n); index += 2; // Wastes one entry according to spec return ret; }
public void visitConstantDouble(ConstantDouble obj){ if (obj.getTag() != Constants.CONSTANT_Double){ throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'."); } //no indices to check } public void visitConstantNameAndType(ConstantNameAndType obj){
@Override public void visitConstantDouble(final ConstantDouble constant) { stack.push(constant); constant.accept(visitor); stack.pop(); }
/** * Add a new double constant to the ConstantPool, if it is not already in there. * * @param n Double number to add * @return index of entry */ public int addDouble( final double n ) { int ret; if ((ret = lookupDouble(n)) != -1) { return ret; // Already in CP } adjustSize(); ret = index; constants[index] = new ConstantDouble(n); index += 2; // Wastes one entry according to spec return ret; }
@Override public void visitConstantDouble(final ConstantDouble obj) { if (obj.getTag() != Const.CONSTANT_Double) { throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'."); } //no indices to check } @Override
public void visitConstantDouble(ConstantDouble constant) { stack.push(constant); constant.accept(visitor); stack.pop(); }
Constant c = this.getConstantRefOperand(); if (c instanceof ConstantDouble) { constValue = ((ConstantDouble) c).getBytes(); } else if (c instanceof ConstantFloat) { constValue = ((ConstantFloat) c).getBytes();
/** * Read one constant from the given file, the type depends on a tag byte. * * @param file Input stream * @return Constant object */ static final Constant readConstant(DataInputStream file) throws IOException, ClassFormatException { byte b = file.readByte(); // Read tag byte switch(b) { case Constants.CONSTANT_Class: return new ConstantClass(file); case Constants.CONSTANT_Fieldref: return new ConstantFieldref(file); case Constants.CONSTANT_Methodref: return new ConstantMethodref(file); case Constants.CONSTANT_InterfaceMethodref: return new ConstantInterfaceMethodref(file); case Constants.CONSTANT_String: return new ConstantString(file); case Constants.CONSTANT_Integer: return new ConstantInteger(file); case Constants.CONSTANT_Float: return new ConstantFloat(file); case Constants.CONSTANT_Long: return new ConstantLong(file); case Constants.CONSTANT_Double: return new ConstantDouble(file); case Constants.CONSTANT_NameAndType: return new ConstantNameAndType(file); case Constants.CONSTANT_Utf8: return new ConstantUtf8(file); default: throw new ClassFormatException("Invalid byte tag in constant pool: " + b); } } }
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 new ConstantLong(dataInput); case Const.CONSTANT_Double: return new ConstantDouble(dataInput); case Const.CONSTANT_NameAndType: return new ConstantNameAndType(dataInput);
@Override public void sawOpcode(int seen) { if (seen == Const.LDC || seen == Const.LDC_W || seen == Const.LDC2_W) { Constant c = getConstantRefOperand(); if (c instanceof ConstantFloat) { checkConst(((ConstantFloat) c).getBytes()); } else if (c instanceof ConstantDouble) { checkConst(((ConstantDouble) c).getBytes()); } return; } // Lower priority if the constant is put into array immediately or after the boxing: // this is likely to be just similar number in some predefined dataset (like lookup table) if(seen == Const.INVOKESTATIC && lastBug != null) { if (getNextOpcode() == Const.AASTORE && getNameConstantOperand().equals("valueOf") && (getClassConstantOperand().equals("java/lang/Double") || getClassConstantOperand().equals( "java/lang/Float"))) { lastBug = ((BugInstance)lastBug.clone()); lastBug.setPriority(lastPriority+1); bugAccumulator.forgetLastBug(); bugAccumulator.accumulateBug(lastBug, this); } } lastBug = null; }
floatConstant = ((ConstantFloat) constantRefOperand).getBytes(); } else if (constantRefOperand instanceof ConstantDouble) { doubleConstant = ((ConstantDouble) constantRefOperand).getBytes(); } else if (constantRefOperand instanceof ConstantString) { int s = ((ConstantString) constantRefOperand).getStringIndex();
randomNextIntState = 4; } else if (seen == Const.LDC2_W && getConstantRefOperand() instanceof ConstantDouble && ((ConstantDouble) getConstantRefOperand()).getBytes() == Integer.MIN_VALUE) { randomNextIntState = 0; } else {
/** * Initialize from another object. */ public ConstantDouble(final ConstantDouble c) { this(c.getBytes()); }
/** * Initialize from another object. */ public ConstantDouble(ConstantDouble c) { this(c.getBytes()); }
/** * Look for ConstantDouble in ConstantPool. * * @param n Double number to look for * @return index on success, -1 otherwise */ public int lookupDouble(double n) { long bits = Double.doubleToLongBits(n); for(int i=1; i < index; i++) { if(constants[i] instanceof ConstantDouble) { ConstantDouble c = (ConstantDouble)constants[i]; if(Double.doubleToLongBits(c.getBytes()) == bits) return i; } } return -1; }
/** * Look for ConstantDouble in ConstantPool. * * @param n Double number to look for * @return index on success, -1 otherwise */ public int lookupDouble( final double n ) { final long bits = Double.doubleToLongBits(n); for (int i = 1; i < index; i++) { if (constants[i] instanceof ConstantDouble) { final ConstantDouble c = (ConstantDouble) constants[i]; if (Double.doubleToLongBits(c.getBytes()) == bits) { 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); } }