Groovy
  1. Groovy
  2. GROOVY-7793

Compiler compiles class with private abstract method

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.11
    • Fix Version/s: 2.4.7
    • Component/s: bytecode, Compiler
    • Labels:
      None
    • Environment:
      - OS X
      - Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
      - IntelliJ Idea 14 CE \w Groovy plugin
      - Gradle 2.2

      Description

      Using Groovy and JDBI in following class:

      ItemDAO.groovy
      abstract class ItemDAO {
          @SqlUpdate("...")
          @GetGeneratedKeys
          private abstract long insertItem(@BindBean Item item)
      }
      

      When class is used JDBI will create proxy-implementation based on the the abstract class (or interface).

      It will compile without any issues, but running it causes (shown below) class-loading/verify error. This is programmers fault to have "private abstract" methods, but I guess Groovy-compiler should not let this thru? Maybe IntelliJ Idea groovy-plugin should say it's illegal as well?

      I haven't tried this with the latest Groovy-version but unless it has been specifically fixed it might still occur?

      Exception in thread "main" java.lang.ClassFormatError: Method insertDish in class com/company/ItemDAO has illegal modifiers: 0x402
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
      at java.lang.Class.getDeclaredMethods(Class.java:1975)
      at org.codehaus.groovy.reflection.CachedClass$3$1.run(CachedClass.java:85)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:82)
      at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:80)
      at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
      at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
      at org.codehaus.groovy.reflection.CachedClass.getMethods(CachedClass.java:251)
      at groovy.lang.MetaClassImpl.populateMethods(MetaClassImpl.java:390)
      at groovy.lang.MetaClassImpl.fillMethodIndex(MetaClassImpl.java:340)
      at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3224)
      at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:222)
      at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:253)
      at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:255)
      at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:859)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallConstructorSite(CallSiteArray.java:84)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:194)

        Activity

        Hide
        ASF GitHub Bot added a comment -

        GitHub user andresteingress opened a pull request:

        https://github.com/apache/groovy/pull/328

        GROOVY-7793: Compiler compiles class with private abstract method

        This PR adds some logic to the class completion verifier that adds an error to the error collector when private abstract methods are detected in abstract classes or enums (for interfaces such a check is already available).

        You can merge this pull request into a Git repository by running:

        $ git pull https://github.com/andresteingress/groovy GROOVY-7793

        Alternatively you can review and apply these changes as the patch at:

        https://github.com/apache/groovy/pull/328.patch

        To close this pull request, make a commit to your master/trunk branch
        with (at least) the following in the commit message:

        This closes #328


        commit 81945cb177a588bb6d7ff0a5868691ed92d89260
        Author: Andre Steingress <me@andresteingress.com>
        Date: 2016-05-04T21:17:03Z

        GROOVY-7793: Compiler compiles class with private abstract method


        Show
        ASF GitHub Bot added a comment - GitHub user andresteingress opened a pull request: https://github.com/apache/groovy/pull/328 GROOVY-7793 : Compiler compiles class with private abstract method This PR adds some logic to the class completion verifier that adds an error to the error collector when private abstract methods are detected in abstract classes or enums (for interfaces such a check is already available). You can merge this pull request into a Git repository by running: $ git pull https://github.com/andresteingress/groovy GROOVY-7793 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/groovy/pull/328.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #328 commit 81945cb177a588bb6d7ff0a5868691ed92d89260 Author: Andre Steingress <me@andresteingress.com> Date: 2016-05-04T21:17:03Z GROOVY-7793 : Compiler compiles class with private abstract method
        Hide
        ASF GitHub Bot added a comment -

        Github user PascalSchumacher commented on a diff in the pull request:

        https://github.com/apache/groovy/pull/328#discussion_r62416234

        — Diff: src/test/org/codehaus/groovy/classgen/ClassCompletionVerifierTest.java —
        @@ -73,13 +73,22 @@
        "Method 'prom' is protected but should be public in interface 'zzz'.";
        private static final String EXPECTED_PRIVATE_METHOD_ERROR_MESSAGE =
        "Method 'prim' is private but should be public in interface 'zzz'.";
        + private static final String EXPECTED_ABSTRACT_PRIVATE_METHOD_ERROR_MESSAGE =
        + "Method 'y' from class 'X' must not be private as it is declared as abstract method.";
        — End diff –

        Should this be "... as an abstract method"?

        Show
        ASF GitHub Bot added a comment - Github user PascalSchumacher commented on a diff in the pull request: https://github.com/apache/groovy/pull/328#discussion_r62416234 — Diff: src/test/org/codehaus/groovy/classgen/ClassCompletionVerifierTest.java — @@ -73,13 +73,22 @@ "Method 'prom' is protected but should be public in interface 'zzz'."; private static final String EXPECTED_PRIVATE_METHOD_ERROR_MESSAGE = "Method 'prim' is private but should be public in interface 'zzz'."; + private static final String EXPECTED_ABSTRACT_PRIVATE_METHOD_ERROR_MESSAGE = + "Method 'y' from class 'X' must not be private as it is declared as abstract method."; — End diff – Should this be "... as an abstract method"?
        Hide
        ASF GitHub Bot added a comment -

        Github user andresteingress commented on a diff in the pull request:

        https://github.com/apache/groovy/pull/328#discussion_r62419225

        — Diff: src/test/org/codehaus/groovy/classgen/ClassCompletionVerifierTest.java —
        @@ -73,13 +73,22 @@
        "Method 'prom' is protected but should be public in interface 'zzz'.";
        private static final String EXPECTED_PRIVATE_METHOD_ERROR_MESSAGE =
        "Method 'prim' is private but should be public in interface 'zzz'.";
        + private static final String EXPECTED_ABSTRACT_PRIVATE_METHOD_ERROR_MESSAGE =
        + "Method 'y' from class 'X' must not be private as it is declared as abstract method.";
        — End diff –

        Yes, "as an" sounds more correct, I will fix it.

        Show
        ASF GitHub Bot added a comment - Github user andresteingress commented on a diff in the pull request: https://github.com/apache/groovy/pull/328#discussion_r62419225 — Diff: src/test/org/codehaus/groovy/classgen/ClassCompletionVerifierTest.java — @@ -73,13 +73,22 @@ "Method 'prom' is protected but should be public in interface 'zzz'."; private static final String EXPECTED_PRIVATE_METHOD_ERROR_MESSAGE = "Method 'prim' is private but should be public in interface 'zzz'."; + private static final String EXPECTED_ABSTRACT_PRIVATE_METHOD_ERROR_MESSAGE = + "Method 'y' from class 'X' must not be private as it is declared as abstract method."; — End diff – Yes, "as an" sounds more correct, I will fix it.
        Hide
        ASF GitHub Bot added a comment -

        Github user asfgit closed the pull request at:

        https://github.com/apache/groovy/pull/328

        Show
        ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/groovy/pull/328
        Hide
        Pascal Schumacher added a comment -

        Pull request merged. Thanks!

        Show
        Pascal Schumacher added a comment - Pull request merged. Thanks!

          People

          • Assignee:
            Pascal Schumacher
            Reporter:
            Simo Tuokko
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development