You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Jason Copenhaver <ja...@charthop.com.INVALID> on 2023/02/08 16:13:45 UTC

[bcel] Invalid Method Signature when parentheses are in method name

I've run into an issue when using BCEL on the results of the below Kotlin
code.

class test {
    fun takeABlock(a: () -> Unit) {
        a()
    }

    fun `method name with () in it`() {
        takeABlock { println("other test") }
    }

    fun `method name without parens`() {
        takeABlock { println("other test") }
    }
}

Three class files are produced.

test$method name with () in it$1.class
test$method name without parens$1.class
test.class

When i use the examples/JasminVisitor.java against `test$method name with
() in it$1.class` with a small patch to add a `field.getType()` call to the
`visitField` method  I get the below stack trace.

Exception in thread "main" org.apache.bcel.classfile.ClassFormatException:
Invalid method signature:  in it$1;
at org.apache.bcel.classfile.Utility.typeOfSignature(Utility.java:1284)
at org.apache.bcel.generic.Type.getType(Type.java:227)
at org.apache.bcel.generic.Type.getReturnType(Type.java:151)
at org.apache.bcel.classfile.Field.getType(Field.java:150)
at JasminVisitor.visitField(JasminVisitor.java:287)
at org.apache.bcel.classfile.Field.accept(Field.java:113)
at
org.apache.bcel.classfile.DescendingVisitor.visitField(DescendingVisitor.java:311)
at org.apache.bcel.classfile.Field.accept(Field.java:113)
at
org.apache.bcel.classfile.DescendingVisitor.lambda$accept$0(DescendingVisitor.java:44)
at
java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at
java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
at
org.apache.bcel.classfile.DescendingVisitor.accept(DescendingVisitor.java:44)
at
org.apache.bcel.classfile.DescendingVisitor.visitJavaClass(DescendingVisitor.java:335)
at org.apache.bcel.classfile.JavaClass.accept(JavaClass.java:251)
at
org.apache.bcel.classfile.DescendingVisitor.visit(DescendingVisitor.java:77)
at JasminVisitor.disassemble(JasminVisitor.java:109)
at JasminVisitor.main(JasminVisitor.java:82)

Thanks,
Jason C

Re: [bcel] Invalid Method Signature when parentheses are in method name

Posted by Gary Gregory <ga...@gmail.com>.
Thanks Jason!

Gary

On Wed, Feb 8, 2023, 19:31 Jason Copenhaver
<ja...@charthop.com.invalid> wrote:

> I've created a PR that repros at
> https://github.com/apache/commons-bcel/pull/205
>
> Jason C
>
> On Wed, Feb 8, 2023 at 3:33 PM Gary Gregory <ga...@gmail.com>
> wrote:
>
> > Hi Jason,
> >
> > The best path forward would be for you to create a PR on GitHub with a
> > failing unit test. That will let us reproduce your issue in the simplest
> > fashion. Also make sure you are using the last version, 6.7.0.
> >
> > Thank you,
> > Gary
> >
> > On Wed, Feb 8, 2023, 11:14 Jason Copenhaver
> > <ja...@charthop.com.invalid> wrote:
> >
> > > I've run into an issue when using BCEL on the results of the below
> Kotlin
> > > code.
> > >
> > > class test {
> > >     fun takeABlock(a: () -> Unit) {
> > >         a()
> > >     }
> > >
> > >     fun `method name with () in it`() {
> > >         takeABlock { println("other test") }
> > >     }
> > >
> > >     fun `method name without parens`() {
> > >         takeABlock { println("other test") }
> > >     }
> > > }
> > >
> > > Three class files are produced.
> > >
> > > test$method name with () in it$1.class
> > > test$method name without parens$1.class
> > > test.class
> > >
> > > When i use the examples/JasminVisitor.java against `test$method name
> with
> > > () in it$1.class` with a small patch to add a `field.getType()` call to
> > the
> > > `visitField` method  I get the below stack trace.
> > >
> > > Exception in thread "main"
> > org.apache.bcel.classfile.ClassFormatException:
> > > Invalid method signature:  in it$1;
> > > at org.apache.bcel.classfile.Utility.typeOfSignature(Utility.java:1284)
> > > at org.apache.bcel.generic.Type.getType(Type.java:227)
> > > at org.apache.bcel.generic.Type.getReturnType(Type.java:151)
> > > at org.apache.bcel.classfile.Field.getType(Field.java:150)
> > > at JasminVisitor.visitField(JasminVisitor.java:287)
> > > at org.apache.bcel.classfile.Field.accept(Field.java:113)
> > > at
> > >
> > >
> >
> org.apache.bcel.classfile.DescendingVisitor.visitField(DescendingVisitor.java:311)
> > > at org.apache.bcel.classfile.Field.accept(Field.java:113)
> > > at
> > >
> > >
> >
> org.apache.bcel.classfile.DescendingVisitor.lambda$accept$0(DescendingVisitor.java:44)
> > > at
> > >
> > >
> >
> java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
> > > at
> > >
> > >
> >
> java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
> > > at
> > >
> > >
> >
> org.apache.bcel.classfile.DescendingVisitor.accept(DescendingVisitor.java:44)
> > > at
> > >
> > >
> >
> org.apache.bcel.classfile.DescendingVisitor.visitJavaClass(DescendingVisitor.java:335)
> > > at org.apache.bcel.classfile.JavaClass.accept(JavaClass.java:251)
> > > at
> > >
> > >
> >
> org.apache.bcel.classfile.DescendingVisitor.visit(DescendingVisitor.java:77)
> > > at JasminVisitor.disassemble(JasminVisitor.java:109)
> > > at JasminVisitor.main(JasminVisitor.java:82)
> > >
> > > Thanks,
> > > Jason C
> > >
> >
>

Re: [bcel] Invalid Method Signature when parentheses are in method name

Posted by Jason Copenhaver <ja...@charthop.com.INVALID>.
I've created a PR that repros at
https://github.com/apache/commons-bcel/pull/205

Jason C

On Wed, Feb 8, 2023 at 3:33 PM Gary Gregory <ga...@gmail.com> wrote:

> Hi Jason,
>
> The best path forward would be for you to create a PR on GitHub with a
> failing unit test. That will let us reproduce your issue in the simplest
> fashion. Also make sure you are using the last version, 6.7.0.
>
> Thank you,
> Gary
>
> On Wed, Feb 8, 2023, 11:14 Jason Copenhaver
> <ja...@charthop.com.invalid> wrote:
>
> > I've run into an issue when using BCEL on the results of the below Kotlin
> > code.
> >
> > class test {
> >     fun takeABlock(a: () -> Unit) {
> >         a()
> >     }
> >
> >     fun `method name with () in it`() {
> >         takeABlock { println("other test") }
> >     }
> >
> >     fun `method name without parens`() {
> >         takeABlock { println("other test") }
> >     }
> > }
> >
> > Three class files are produced.
> >
> > test$method name with () in it$1.class
> > test$method name without parens$1.class
> > test.class
> >
> > When i use the examples/JasminVisitor.java against `test$method name with
> > () in it$1.class` with a small patch to add a `field.getType()` call to
> the
> > `visitField` method  I get the below stack trace.
> >
> > Exception in thread "main"
> org.apache.bcel.classfile.ClassFormatException:
> > Invalid method signature:  in it$1;
> > at org.apache.bcel.classfile.Utility.typeOfSignature(Utility.java:1284)
> > at org.apache.bcel.generic.Type.getType(Type.java:227)
> > at org.apache.bcel.generic.Type.getReturnType(Type.java:151)
> > at org.apache.bcel.classfile.Field.getType(Field.java:150)
> > at JasminVisitor.visitField(JasminVisitor.java:287)
> > at org.apache.bcel.classfile.Field.accept(Field.java:113)
> > at
> >
> >
> org.apache.bcel.classfile.DescendingVisitor.visitField(DescendingVisitor.java:311)
> > at org.apache.bcel.classfile.Field.accept(Field.java:113)
> > at
> >
> >
> org.apache.bcel.classfile.DescendingVisitor.lambda$accept$0(DescendingVisitor.java:44)
> > at
> >
> >
> java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
> > at
> >
> >
> java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
> > at
> >
> >
> org.apache.bcel.classfile.DescendingVisitor.accept(DescendingVisitor.java:44)
> > at
> >
> >
> org.apache.bcel.classfile.DescendingVisitor.visitJavaClass(DescendingVisitor.java:335)
> > at org.apache.bcel.classfile.JavaClass.accept(JavaClass.java:251)
> > at
> >
> >
> org.apache.bcel.classfile.DescendingVisitor.visit(DescendingVisitor.java:77)
> > at JasminVisitor.disassemble(JasminVisitor.java:109)
> > at JasminVisitor.main(JasminVisitor.java:82)
> >
> > Thanks,
> > Jason C
> >
>

Re: [bcel] Invalid Method Signature when parentheses are in method name

Posted by Gary Gregory <ga...@gmail.com>.
Hi Jason,

The best path forward would be for you to create a PR on GitHub with a
failing unit test. That will let us reproduce your issue in the simplest
fashion. Also make sure you are using the last version, 6.7.0.

Thank you,
Gary

On Wed, Feb 8, 2023, 11:14 Jason Copenhaver
<ja...@charthop.com.invalid> wrote:

> I've run into an issue when using BCEL on the results of the below Kotlin
> code.
>
> class test {
>     fun takeABlock(a: () -> Unit) {
>         a()
>     }
>
>     fun `method name with () in it`() {
>         takeABlock { println("other test") }
>     }
>
>     fun `method name without parens`() {
>         takeABlock { println("other test") }
>     }
> }
>
> Three class files are produced.
>
> test$method name with () in it$1.class
> test$method name without parens$1.class
> test.class
>
> When i use the examples/JasminVisitor.java against `test$method name with
> () in it$1.class` with a small patch to add a `field.getType()` call to the
> `visitField` method  I get the below stack trace.
>
> Exception in thread "main" org.apache.bcel.classfile.ClassFormatException:
> Invalid method signature:  in it$1;
> at org.apache.bcel.classfile.Utility.typeOfSignature(Utility.java:1284)
> at org.apache.bcel.generic.Type.getType(Type.java:227)
> at org.apache.bcel.generic.Type.getReturnType(Type.java:151)
> at org.apache.bcel.classfile.Field.getType(Field.java:150)
> at JasminVisitor.visitField(JasminVisitor.java:287)
> at org.apache.bcel.classfile.Field.accept(Field.java:113)
> at
>
> org.apache.bcel.classfile.DescendingVisitor.visitField(DescendingVisitor.java:311)
> at org.apache.bcel.classfile.Field.accept(Field.java:113)
> at
>
> org.apache.bcel.classfile.DescendingVisitor.lambda$accept$0(DescendingVisitor.java:44)
> at
>
> java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
> at
>
> java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
> at
>
> org.apache.bcel.classfile.DescendingVisitor.accept(DescendingVisitor.java:44)
> at
>
> org.apache.bcel.classfile.DescendingVisitor.visitJavaClass(DescendingVisitor.java:335)
> at org.apache.bcel.classfile.JavaClass.accept(JavaClass.java:251)
> at
>
> org.apache.bcel.classfile.DescendingVisitor.visit(DescendingVisitor.java:77)
> at JasminVisitor.disassemble(JasminVisitor.java:109)
> at JasminVisitor.main(JasminVisitor.java:82)
>
> Thanks,
> Jason C
>