Uploaded image for project: 'Commons BCEL'
  1. Commons BCEL
  2. BCEL-68

Unable to generate method that returns an array of integers

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.1
    • 5.2
    • Main
    • None

    Description

      I'm trying to generate the following code use BCEL:

      package bci;

      public class Test {

      public int[] getArray()

      { return new int[1]; }

      public static void main(String[] args) {
      }
      }

      I use BCELIfier to generate the code that creates Test. The snippet that creates getArray is

      private void createMethod_2() {
      InstructionList il = new InstructionList();
      MethodGen method = new MethodGen(ACC_PUBLIC, new ArrayType(T_INT, 1), Type.NO_ARGS, new
      String[] { }, "getArray", "bci.Test", il, _cp);

      InstructionHandle ih_0 = il.append(new PUSH(_cp, 1));
      il.append(_factory.createNewArray(new ArrayType(T_INT, 1), (short) 1));
      InstructionHandle ih_3 = il.append(_factory.createReturn(Type.OBJECT));
      method.setMaxStack();
      method.setMaxLocals();
      _cg.addMethod(method.getMethod());
      il.dispose();
      }

      I run TestCreator (generated by BCELIfier) and execute Test, which triggers the following error:

      Exception in thread "main" java.lang.VerifyError: (class: bci/Test, method: getArray signature: ()[I)
      Wrong return type in function

      If I return null rather than the array, everything is perfectly allright.

      Attachments

        Activity

          People

            issues@commons.apache.org Apache Commons Developers
            cavengene@yahoo.de cavengene
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: