7 Replies Latest reply on Mar 6, 2008 10:18 AM by Shigeru Chiba

    How to create CtClass java.lang.Object

    Vlad Skarzhevskyy Newbie

      Hi Shigeru
      How can one create CtClass that does not have default Superclass java.lang.Object?

      By deafaul ClassFile.initSuperclass() assign java.lang.Object as super class even when I'm creating "java.lang.ObjectÐ.

      In general we want to create J2ME CLDC API classes base on its descriptors.
      API descriptors are defined in XML so we just need to create STUB classes.

      Vlad Skarzhevskyy
      http://www.microemu.org/
      http://jour.sourceforge.net/signature.html

        • 1. Re: How to create CtClass java.lang.Object
          Shigeru Chiba Expert

          You can change the super class just after you create
          a new CtClass object. Some factory methods like
          ClassPool#makeClass() takes a super class as a
          parameter. Don't these ways satisfy your needs?

          • 2. Re: How to create CtClass java.lang.Object
            Vlad Skarzhevskyy Newbie

            This is exactly what I do:

            ---
            klass = classPool.makeClass("java.lang.Object", null);
            ---


            When this is called the class is created but when I see bytecode
            System.out.println(klass.getSuperclass())
            ->> java.lang.Object

            ----
            public class java.lang.Object extends java.lang.Object {
            ....
            }
            --


            or when try to run proguard that is using this classe It goes into stackOverflowError parsing it.


            --
            There should be a special case to handle the java.lang.Object class!

            • 3. Re: How to create CtClass java.lang.Object
              Shigeru Chiba Expert

              Ah.. it is not allowed in J2SE to create another version
              of java.lang.Object.

              For your purpose, what about:

              CtClass klass = classPool.get("java.lang.Object");

              You can modify klass as you want.

              • 4. Re: How to create CtClass java.lang.Object
                Vlad Skarzhevskyy Newbie

                I know that in J2SE it should not work!

                BUT We are creating J2ME CLDC API classes!
                The java/lang/Object.class should be created and written to the disk then it would be used to build MIDlet applications.

                Created Object class is not used at runtime! The class is only used during J2ME build and it should have signature different from one in J2SE!

                We have a process to create API stub classes. (No implementation classes only proper signature) The classes signature is defined in XML and then exported to .classes using javassist.

                Really need your help to solve this last outstanding problem!

                Vlad

                PS
                http://www.microemu.org/ MicroEmulator is a pure Java implementation of Java ME in Java SE. The CLDC API classes is a subset of J2SE.

                The open source project ProGuard has been updated to allow preverification of J2ME applications. We are only one step from creating complete Open Source J2ME build process. The only missing point is LGPL or Apache CLDC API classes.

                The phoneME classes can't be used because they are GPL. So we are creating the process to solve licenses problem. classes signature is not part of license so we need to create proper CLDC classes from signature.


                PPS
                "it is not allowed in J2SE" Fine but this javassist code is working fine:
                ---
                klass = classPool.makeClass("java.lang.Object", null);
                klass.writeFile("java/lang/Object.class");
                ---

                But the file created is not right!
                It creates "class Object extends Object"

                • 5. Re: How to create CtClass java.lang.Object
                  Shigeru Chiba Expert

                  So what about reusing an existing CtClass
                  that represents java.lang.Object?

                  By default, any ClassPool contains java.lang.Object.
                  My idea is to get that CtClass object from the pool
                  and modify it to be what you need.

                  • 6. Re: How to create CtClass java.lang.Object
                    Vlad Skarzhevskyy Newbie

                    Thanks!
                    This approach works fine!
                    Regards,
                    Vlad

                    PS
                    I see you not uploading latest versions to maven repozitory. Do you want to delegate this task to me?

                    • 7. Re: How to create CtClass java.lang.Object
                      Shigeru Chiba Expert

                       

                      I see you not uploading latest versions to maven repozitory. Do you want to delegate this task to me?


                      Thank you. But I think someone else should be responsible
                      for this.