/** * Add a new Utf8 constant to the ConstantPool, if it is not already in there. * * @param n Utf8 string to add * @return index of entry */ public int addUtf8( final String n ) { int ret; if ((ret = lookupUtf8(n)) != -1) { return ret; // Already in CP } adjustSize(); ret = index; constants[index++] = new ConstantUtf8(n); if (!utf8_table.containsKey(n)) { utf8_table.put(n, new Index(ret)); } return ret; }
/** * Add a new Utf8 constant to the ConstantPool, if it is not already in there. * * @param n Utf8 string to add * @return index of entry */ public int addUtf8(String n) { int ret; if((ret = lookupUtf8(n)) != -1) return ret; // Already in CP adjustSize(); ret = index; constants[index++] = new ConstantUtf8(n); utf8_table.put(n, new Index(ret)); return ret; }
@Override public boolean shouldAnalyzeClass(ClassContext classContext) { ConstantPoolGen constantPoolGen = classContext.getConstantPoolGen(); for (String requiredClass : REQUIRED_CLASSES) { if (constantPoolGen.lookupUtf8(requiredClass) != -1) { String className = classContext.getClassDescriptor().getDottedClassName(); return !InterfaceUtils.isSubtype(className, XssJspDetector.JSP_PARENT_CLASSES); } } return false; } }
@Override public boolean shouldAnalyzeClass(ClassContext classContext) { ConstantPoolGen constantPoolGen = classContext.getConstantPoolGen(); for (String requiredClass : REQUIRED_CLASSES) { if (constantPoolGen.lookupUtf8(requiredClass) != -1) { String className = classContext.getClassDescriptor().getDottedClassName(); return !InterfaceUtils.isSubtype(className, XssJspDetector.JSP_PARENT_CLASSES); } } return false; } }
public void testCreateStringElementValue() throws Exception { // Create HelloWorld final ClassGen cg = createClassGen("HelloWorld"); final ConstantPoolGen cp = cg.getConstantPool(); final SimpleElementValueGen evg = new SimpleElementValueGen( ElementValueGen.STRING, cp, "hello"); // Creation of an element like that should leave a new entry in the // cpool assertTrue("Should have the same index in the constantpool but " + evg.getIndex() + "!=" + cp.lookupUtf8("hello"), evg .getIndex() == cp.lookupUtf8("hello")); checkSerialize(evg, cp); }
public void testCreateEnumElementValue() throws Exception { final ClassGen cg = createClassGen("HelloWorld"); final ConstantPoolGen cp = cg.getConstantPool(); final ObjectType enumType = new ObjectType("SimpleEnum"); // Supports rainbow // :) final EnumElementValueGen evg = new EnumElementValueGen(enumType, "Red", cp); // Creation of an element like that should leave a new entry in the // cpool assertTrue( "The new ElementValue value index should match the contents of the constantpool but " + evg.getValueIndex() + "!=" + cp.lookupUtf8("Red"), evg.getValueIndex() == cp.lookupUtf8("Red")); // BCELBUG: Should the class signature or class name be in the constant // pool? (see note in ConstantPool) // assertTrue("The new ElementValue type index should match the contents // of the constantpool but "+ // evg.getTypeIndex()+"!="+cp.lookupClass(enumType.getSignature()), // evg.getTypeIndex()==cp.lookupClass(enumType.getSignature())); checkSerialize(evg, cp); }