F
Florian Weimer
I'm trying to create, using the ASM library, a class which calls
methods in an another class specified at run-time (passed as its Class
object). I don't think my problem is ASM-related, that's why I'm
asking here.
My approach works just fine when the class being called is declared
"public", but not if it's a local class in some member method.
The local class I'm trying to call looks like this in javap:
class de.enyo.pcre.PatternTest$1T extends java.lang.Object
SourceFile: "PatternTest.java"
InnerClass:
#87= #1; //T=class de/enyo/pcre/PatternTest$1T
EnclosingMethod: length = 0x4
00 59 00 5B
minor version: 0
major version: 50
Constant pool:
const #1 = class #2; // de/enyo/pcre/PatternTest$1T
[...]
const #22 = Asciz ()V;
[...]
const #87 = Asciz T;
const #88 = Asciz EnclosingMethod;
const #89 = class #90; // de/enyo/pcre/PatternTest
const #90 = Asciz de/enyo/pcre/PatternTest;
const #91 = NameAndType #92:#22;// testDispatcher)V
const #92 = Asciz testDispatcher;
The run-time generated class looks like this:
public class de.enyo.pcre.PatternTest$1T$RegExpDispatcher extends de.enyo.pcre.DispatcherASM
Signature: length = 0x2
00 03
EnclosingMethod: length = 0x4
00 07 00 0A
InnerClass:
#2; //class de/enyo/pcre/PatternTest$1T$RegExpDispatcher
minor version: 0
major version: 50
Constant pool:
const #1 = Asciz de/enyo/pcre/PatternTest$1T$RegExpDispatcher;
const #2 = class #1; // de/enyo/pcre/PatternTest$1T$RegExpDispatcher
const #3 = Asciz Lde/enyo/pcre/DispatcherASM<de/enyo/pcre/PatternTest$1T>;;
[...]
const #7 = class #6; // de/enyo/pcre/PatternTest
const #8 = Asciz testDispatcher;
const #9 = Asciz ()V;
const #10 = NameAndType #8:#9;// testDispatcher)V
I had hoped that the similarity is sufficient. Howver, executing the
generated class results in an IllegalAccessError exception ("tried to
access class de.enyo.pcre.PatternTest$1T from class
de.enyo.pcre.PatternTest$1T$RegExpDispatcher").
I'm using a trivial class loader which specifies the loader of
PatternTest$1T as its parent. The "public" attribute of the generated
class is required because I need it to instantiate the class.
Any ideas? How can I work around these accessibility checks?
methods in an another class specified at run-time (passed as its Class
object). I don't think my problem is ASM-related, that's why I'm
asking here.
My approach works just fine when the class being called is declared
"public", but not if it's a local class in some member method.
The local class I'm trying to call looks like this in javap:
class de.enyo.pcre.PatternTest$1T extends java.lang.Object
SourceFile: "PatternTest.java"
InnerClass:
#87= #1; //T=class de/enyo/pcre/PatternTest$1T
EnclosingMethod: length = 0x4
00 59 00 5B
minor version: 0
major version: 50
Constant pool:
const #1 = class #2; // de/enyo/pcre/PatternTest$1T
[...]
const #22 = Asciz ()V;
[...]
const #87 = Asciz T;
const #88 = Asciz EnclosingMethod;
const #89 = class #90; // de/enyo/pcre/PatternTest
const #90 = Asciz de/enyo/pcre/PatternTest;
const #91 = NameAndType #92:#22;// testDispatcher)V
const #92 = Asciz testDispatcher;
The run-time generated class looks like this:
public class de.enyo.pcre.PatternTest$1T$RegExpDispatcher extends de.enyo.pcre.DispatcherASM
Signature: length = 0x2
00 03
EnclosingMethod: length = 0x4
00 07 00 0A
InnerClass:
#2; //class de/enyo/pcre/PatternTest$1T$RegExpDispatcher
minor version: 0
major version: 50
Constant pool:
const #1 = Asciz de/enyo/pcre/PatternTest$1T$RegExpDispatcher;
const #2 = class #1; // de/enyo/pcre/PatternTest$1T$RegExpDispatcher
const #3 = Asciz Lde/enyo/pcre/DispatcherASM<de/enyo/pcre/PatternTest$1T>;;
[...]
const #7 = class #6; // de/enyo/pcre/PatternTest
const #8 = Asciz testDispatcher;
const #9 = Asciz ()V;
const #10 = NameAndType #8:#9;// testDispatcher)V
I had hoped that the similarity is sufficient. Howver, executing the
generated class results in an IllegalAccessError exception ("tried to
access class de.enyo.pcre.PatternTest$1T from class
de.enyo.pcre.PatternTest$1T$RegExpDispatcher").
I'm using a trivial class loader which specifies the loader of
PatternTest$1T as its parent. The "public" attribute of the generated
class is required because I need it to instantiate the class.
Any ideas? How can I work around these accessibility checks?