You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/02/26 14:14:27 UTC

[commons-bcel] branch master updated: Exception parsing Kotlin class with 'fun `method name with () in it`()' #205.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git


The following commit(s) were added to refs/heads/master by this push:
     new 28d1f9df Exception parsing Kotlin class with 'fun `method name with () in it`()' #205.
28d1f9df is described below

commit 28d1f9df6aa540d2830db5f7823ebf9d729ccbf3
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Sun Feb 26 09:14:22 2023 -0500

    Exception parsing Kotlin class with 'fun `method name with () in
    it`()' #205.
---
 pom.xml                                            |   6 ++
 src/changes/changes.xml                            |   1 +
 src/main/java/org/apache/bcel/classfile/Field.java |   4 +-
 .../classfile/InvalidMethodSigantureTestCase.java  |  84 +++++++++++++++++++++
 .../kotlin/test$method name with () in it$1.class  | Bin 0 -> 1191 bytes
 5 files changed, 94 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 3f72a932..1637baff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -502,6 +502,12 @@
       <version>3.26.0</version> <!-- last JDK8-compatible version -->
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.jetbrains.kotlin</groupId>
+      <artifactId>kotlin-stdlib</artifactId>
+      <version>1.8.10</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <profiles>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e7ba7058..f88c3a66 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -71,6 +71,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action                  type="fix" dev="markt" due-to="OSS-Fuzz">Ensure that references to the unused constant pool entry after a long/double entry triggers a ClassFormatException, not a NullPointerException.</action>
       <action                  type="fix" dev="markt" due-to="nbauma109">Test and coverage of InstructionFactory #190.</action>
       <action                  type="fix" dev="ggregory" due-to="nbauma109">Verifier: test and coverage for SWAP instruction #188.</action>
+      <action                  type="fix" dev="ggregory" due-to="Jason Copenhaver, Gary Gregory">Exception parsing Kotlin class with 'fun `method name with () in it`()' #205.</action>
       <!-- UPDATE -->
       <action                  type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-parent from 54 to 56 #189, #198.</action>
       <action                  type="update" dev="ggregory" due-to="Dependabot">Bump jna.version from 5.12.1 to 5.13.0 #203.</action>
diff --git a/src/main/java/org/apache/bcel/classfile/Field.java b/src/main/java/org/apache/bcel/classfile/Field.java
index 2afb4f1a..a5cb19d1 100644
--- a/src/main/java/org/apache/bcel/classfile/Field.java
+++ b/src/main/java/org/apache/bcel/classfile/Field.java
@@ -144,10 +144,12 @@ public final class Field extends FieldOrMethod {
     }
 
     /**
+     * See https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.2.2
+     *
      * @return type of field
      */
     public Type getType() {
-        return Type.getReturnType(getSignature());
+        return Type.getType(getSignature());
     }
 
     /**
diff --git a/src/test/java/org/apache/bcel/classfile/InvalidMethodSigantureTestCase.java b/src/test/java/org/apache/bcel/classfile/InvalidMethodSigantureTestCase.java
new file mode 100644
index 00000000..e5ff65fd
--- /dev/null
+++ b/src/test/java/org/apache/bcel/classfile/InvalidMethodSigantureTestCase.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bcel.classfile;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+/**
+ * javap input:
+ *
+ * <pre>
+ * javap "src/test/resources/kotlin/test$method name with () in it$1.class"
+ * </pre>
+ *
+ * javap output:
+ *
+ * <pre>
+ *
+Compiled from "test.kt"
+final class test$method name with () in it$1 extends kotlin.jvm.internal.Lambda implements kotlin.jvm.functions.Function0<kotlin.Unit> {
+  public static final test$method name with () in it$1 INSTANCE;
+  test$method name with () in it$1();
+  public final void invoke();
+  public java.lang.Object invoke();
+  static {};
+ * </pre>
+ */
+public class InvalidMethodSigantureTestCase {
+
+    private static final String CLASS_NAME = "test$method name with () in it$1";
+    private static final String SRC_TEST_RESOURCES_KOTLIN = "src/test/resources/kotlin/";
+
+    class TestVisitor extends org.apache.bcel.classfile.EmptyVisitor {
+        @Override
+        public void visitField(final Field field) {
+            field.getType();
+        }
+    }
+
+    @Test
+    public void testLoadClass() throws Exception {
+        final Path path = Paths.get(SRC_TEST_RESOURCES_KOTLIN);
+        assertTrue(Files.exists(path));
+        assertTrue(Files.isDirectory(path));
+        try (URLClassLoader cl = URLClassLoader.newInstance(new URL[] { path.toUri().toURL() })) {
+            Class.forName(CLASS_NAME, false, cl);
+        }
+    }
+
+    @Test
+    //@Disabled("TODO?")
+    public void testMethodWithParens() throws Exception {
+        try (final InputStream inputStream = Files.newInputStream(Paths.get(SRC_TEST_RESOURCES_KOTLIN, CLASS_NAME + ".class"))) {
+            final ClassParser classParser = new ClassParser(inputStream, CLASS_NAME);
+            final JavaClass javaClass = classParser.parse();
+            final TestVisitor visitor = new TestVisitor();
+            new DescendingVisitor(javaClass, visitor).visit();
+        }
+    }
+}
diff --git a/src/test/resources/kotlin/test$method name with () in it$1.class b/src/test/resources/kotlin/test$method name with () in it$1.class
new file mode 100644
index 00000000..bdfbfeda
Binary files /dev/null and b/src/test/resources/kotlin/test$method name with () in it$1.class differ