Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.ConstantUtf8


                Field[] flds = getClassContext().getJavaClass().getFields();

                for (Field fld : flds) {
                    if (fld.getNameIndex() == nameIdx) {
                        if (!fld.isStatic()) {
                            ConstantUtf8 nameCons = (ConstantUtf8) cp.getConstant(nameIdx);
                            ConstantUtf8 typeCons = (ConstantUtf8) cp.getConstant(ntc.getSignatureIndex());

                            if (alreadyReported.contains(nameCons.getBytes())) {
                                return;
                            }
                            alreadyReported.add(nameCons.getBytes());
                            bugReporter.reportBug(new BugInstance(this,
                                    STRUTS_ACTION_NAME.equals(mtClassName) ? "MTIA_SUSPECT_STRUTS_INSTANCE_FIELD"
                                            : "MTIA_SUSPECT_SERVLET_INSTANCE_FIELD", LOW_PRIORITY)
                            .addField(
                                    new FieldAnnotation(getDottedClassName(), nameCons.getBytes(), typeCons.getBytes(),
                                            false)).addClass(this).addSourceLine(this));
                        }
                        break;
                    }
                }
View Full Code Here


        boolean sawUtilConcurrentLocks = false;
        for (Constant c : jclass.getConstantPool().getConstantPool()) {
            if (c instanceof ConstantMethodref) {
                ConstantMethodref m = (ConstantMethodref) c;
                ConstantClass cl = (ConstantClass) jclass.getConstantPool().getConstant(m.getClassIndex());
                ConstantUtf8 name = (ConstantUtf8) jclass.getConstantPool().getConstant(cl.getNameIndex());
                String nameAsString = name.getBytes();
                if (nameAsString.startsWith("java/util/concurrent/locks")) {
                    sawUtilConcurrentLocks = true;
                }

            }
View Full Code Here

          constraintViolated(o, "Indexing a constant that's not a CONSTANT_Methodref but a '"+c+"'.");
        }
        else{
          // Constants are okay due to pass2.
          ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantMethodref) c).getNameAndTypeIndex()));
          ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()));
          if (cutf8.getBytes().equals(Constants.CONSTRUCTOR_NAME) && (!(o instanceof INVOKESPECIAL)) ){
            constraintViolated(o, "Only INVOKESPECIAL is allowed to invoke instance initialization methods.");
          }
          if ( (! (cutf8.getBytes().equals(Constants.CONSTRUCTOR_NAME)) ) && (cutf8.getBytes().startsWith("<")) ){
            constraintViolated(o, "No method with a name beginning with '<' other than the instance initialization methods may be called by the method invocation instructions.");
          }
        }
      }
      else{ //if (o instanceof INVOKEINTERFACE){
View Full Code Here

      Constant c = cpg.getConstant(o.getIndex());
      if ((c instanceof ConstantClass)){
        constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
      }
      else{
        ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant( ((ConstantClass) c).getNameIndex() ));
        Type t = Type.getType("L"+cutf8.getBytes()+";");
        if (t instanceof ArrayType){
          constraintViolated(o, "NEW must not be used to create an array.");
        }
      }
     
View Full Code Here

        }
        for (int i = 1; i < index; i++) {
            Constant c = constants[i];
            if (c instanceof ConstantString) {
                ConstantString s = (ConstantString) c;
                ConstantUtf8 u8 = (ConstantUtf8) constants[s.getStringIndex()];
                String key = u8.getBytes();
                if (!string_table.containsKey(key)) {
                    string_table.put(key, new Index(i));
                }
            } else if (c instanceof ConstantClass) {
                ConstantClass s = (ConstantClass) c;
                ConstantUtf8 u8 = (ConstantUtf8) constants[s.getNameIndex()];
                String key = u8.getBytes();
                if (!class_table.containsKey(key)) {
                    class_table.put(key, new Index(i));
                }
            } else if (c instanceof ConstantNameAndType) {
                ConstantNameAndType n = (ConstantNameAndType) c;
                ConstantUtf8 u8 = (ConstantUtf8) constants[n.getNameIndex()];
                ConstantUtf8 u8_2 = (ConstantUtf8) constants[n.getSignatureIndex()];
                String key = u8.getBytes() + NAT_DELIM + u8_2.getBytes();
                if (!n_a_t_table.containsKey(key)) {
                    n_a_t_table.put(key, new Index(i));
                }
            } else if (c instanceof ConstantUtf8) {
                ConstantUtf8 u = (ConstantUtf8) c;
                String key = u.getBytes();
                if (!utf8_table.containsKey(key)) {
                    utf8_table.put(key, new Index(i));
                }
            } else if (c instanceof ConstantCP) {
                ConstantCP m = (ConstantCP) c;
                ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
                ConstantNameAndType n = (ConstantNameAndType) constants[m.getNameAndTypeIndex()];
                ConstantUtf8 u8 = (ConstantUtf8) constants[clazz.getNameIndex()];
                String class_name = u8.getBytes().replace('/', '.');
                u8 = (ConstantUtf8) constants[n.getNameIndex()];
                String method_name = u8.getBytes();
                u8 = (ConstantUtf8) constants[n.getSignatureIndex()];
                String signature = u8.getBytes();
                String delim = METHODREF_DELIM;
                if (c instanceof ConstantInterfaceMethodref) {
                    delim = IMETHODREF_DELIM;
                } else if (c instanceof ConstantFieldref) {
                    delim = FIELDREF_DELIM;
View Full Code Here

        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;
    }
View Full Code Here

    public int addConstant( Constant c, ConstantPoolGen cp ) {
        Constant[] constants = cp.getConstantPool().getConstantPool();
        switch (c.getTag()) {
            case Constants.CONSTANT_String: {
                ConstantString s = (ConstantString) c;
                ConstantUtf8 u8 = (ConstantUtf8) constants[s.getStringIndex()];
                return addString(u8.getBytes());
            }
            case Constants.CONSTANT_Class: {
                ConstantClass s = (ConstantClass) c;
                ConstantUtf8 u8 = (ConstantUtf8) constants[s.getNameIndex()];
                return addClass(u8.getBytes());
            }
            case Constants.CONSTANT_NameAndType: {
                ConstantNameAndType n = (ConstantNameAndType) c;
                ConstantUtf8 u8 = (ConstantUtf8) constants[n.getNameIndex()];
                ConstantUtf8 u8_2 = (ConstantUtf8) constants[n.getSignatureIndex()];
                return addNameAndType(u8.getBytes(), u8_2.getBytes());
            }
            case Constants.CONSTANT_Utf8:
                return addUtf8(((ConstantUtf8) c).getBytes());
            case Constants.CONSTANT_Double:
                return addDouble(((ConstantDouble) c).getBytes());
            case Constants.CONSTANT_Float:
                return addFloat(((ConstantFloat) c).getBytes());
            case Constants.CONSTANT_Long:
                return addLong(((ConstantLong) c).getBytes());
            case Constants.CONSTANT_Integer:
                return addInteger(((ConstantInteger) c).getBytes());
            case Constants.CONSTANT_InterfaceMethodref:
            case Constants.CONSTANT_Methodref:
            case Constants.CONSTANT_Fieldref: {
                ConstantCP m = (ConstantCP) c;
                ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
                ConstantNameAndType n = (ConstantNameAndType) constants[m.getNameAndTypeIndex()];
                ConstantUtf8 u8 = (ConstantUtf8) constants[clazz.getNameIndex()];
                String class_name = u8.getBytes().replace('/', '.');
                u8 = (ConstantUtf8) constants[n.getNameIndex()];
                String name = u8.getBytes();
                u8 = (ConstantUtf8) constants[n.getSignatureIndex()];
                String signature = u8.getBytes();
                switch (c.getTag()) {
                    case Constants.CONSTANT_InterfaceMethodref:
                        return addInterfaceMethodref(class_name, name, signature);
                    case Constants.CONSTANT_Methodref:
                        return addMethodref(class_name, name, signature);
View Full Code Here

        }
        // Adapt the class name to the passed value
        ConstantPool cp = clazz.getConstantPool();
        ConstantClass cl = (ConstantClass) cp.getConstant(clazz.getClassNameIndex(),
                Constants.CONSTANT_Class);
        ConstantUtf8 name = (ConstantUtf8) cp.getConstant(cl.getNameIndex(),
                Constants.CONSTANT_Utf8);
        name.setBytes(class_name.replace('.', '/'));
        return clazz;
    }
View Full Code Here

        }
        throw new IllegalArgumentException("Not visiting an instance method call");
    }

    private String getStringFromIndex(DismantleBytecode dbc, int i) {
        ConstantUtf8 name = (ConstantUtf8) dbc.getConstantPool().getConstant(i);
        return name.getBytes();
    }
View Full Code Here

    // Available when visiting a Code
    private Code code;

    protected String getStringFromIndex(int i) {
        ConstantUtf8 name = (ConstantUtf8) constantPool.getConstant(i);
        return name.getBytes();
    }
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.ConstantUtf8

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.