[jira] [Commented] (GROOVY-8632) Groovy 2.5.0 fails to compile Google Java Client sample code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-8632) Groovy 2.5.0 fails to compile Google Java Client sample code

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/GROOVY-8632?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16506743#comment-16506743 ]

John Wagenleitner commented on GROOVY-8632:
-------------------------------------------

This issue is with the new ASM class file based resolver that is turned on by default in 2.5.0. As it visits classes it stores inner class access modifiers by the short class name (i.e., {{Builder}}).

https://github.com/apache/groovy/blob/334b5df0af1e6f06aeca101136f01201312a0259/src/main/java/org/codehaus/groovy/ast/decompiled/AsmDecompiler.java#L106

When building the actual {{ClassNode}} for inner classes it tries to determine if the inner class is static by finding the outer class and looking in it’s {{innerClassModifiers}} map.

https://github.com/apache/groovy/blob/334b5df0af1e6f06aeca101136f01201312a0259/src/main/java/org/codehaus/groovy/ast/decompiled/DecompiledClassNode.java#L58-L75

The problem is that it only stores the short name rather than the fully qualified name. A class file may contain INNERCLASS references to another classes’ inner class and it could have the same name, which is the case for the Google API class {{AnalyticsReporting}} class. In that case that other class’ abstract modifier is being picked up and causing the reported error.

{code:java}
// class version 49.0 (49)
// access flags 0x21
public class com/google/api/services/analyticsreporting/v4/AnalyticsReporting extends com/google/api/client/googleapis/services/json/AbstractGoogleJsonClient  {

  // compiled from: AnalyticsReporting.java
  // access flags 0x19
  public final static INNERCLASS com/google/api/services/analyticsreporting/v4/AnalyticsReporting$Builder com/google/api/services/analyticsreporting/v4/AnalyticsReporting Builder
  // access flags 0x1
  public INNERCLASS com/google/api/services/analyticsreporting/v4/AnalyticsReporting$Reports com/google/api/services/analyticsreporting/v4/AnalyticsReporting Reports
  // access flags 0x409
  public static abstract INNERCLASS com/google/api/client/googleapis/services/json/AbstractGoogleJsonClient$Builder com/google/api/client/googleapis/services/json/AbstractGoogleJsonClient Builder
….
….
{code}

While this could be fixed by storing the fully qualified name, the logic might be simplified since the class file for inner classes contain a self referenced INNERCLASS entry. So it not necessary to resolve the outer class. During the {{visitInnerClass}} call if the top level class name matches the inner class name, those modifiers could be stored and used later to determine the full access modifiers for inner classes.

{code:java}
// class version 49.0 (49)
// access flags 0x31
public final class com/google/api/services/analyticsreporting/v4/AnalyticsReporting$Builder extends com/google/api/client/googleapis/services/json/AbstractGoogleJsonClient$Builder  {

  // compiled from: AnalyticsReporting.java
  // access flags 0x19
  public final static INNERCLASS com/google/api/services/analyticsreporting/v4/AnalyticsReporting$Builder com/google/api/services/analyticsreporting/v4/AnalyticsReporting Builder
  // access flags 0x409
  public static abstract INNERCLASS com/google/api/client/googleapis/services/json/AbstractGoogleJsonClient$Builder com/google/api/client/googleapis/services/json/AbstractGoogleJsonClient Builder
  // access flags 0x409
  public static abstract INNERCLASS com/google/api/client/googleapis/services/AbstractGoogleClient$Builder com/google/api/client/googleapis/services/AbstractGoogleClient Builder
….
….
{code}


> Groovy 2.5.0 fails to compile Google Java Client sample code
> ------------------------------------------------------------
>
>                 Key: GROOVY-8632
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8632
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.5.0
>         Environment: Ubuntu 18.04, Oracle Java 1.8.0_171-b11, Groovy 2.5.0
>            Reporter: Robert Kasanicky
>            Assignee: John Wagenleitner
>            Priority: Major
>
> I have been using Google Java Client libraries with Groovy 2.4.x successfully but now I'm getting multiple compilation errors when trying to upgrade to Groovy 2.5.0. Note that none of the classes mentioned are actually abstract although the 2.5.0 compiler clearly thinks they are.
> {code}
> @Grab('com.google.apis:google-api-services-analyticsreporting:v4-rev124-1.23.0')
> import com.google.api.services.analyticsreporting.v4.AnalyticsReporting
> @Grab('com.google.apis:google-api-services-sheets:v4-rev525-1.23.0')
> import com.google.api.services.sheets.v4.Sheets
> @Grab('com.google.apis:google-api-services-drive:v3-rev120-1.23.0')
> import com.google.api.services.drive.Drive
> final HTTP_TRANSPORT = null
> final JSON_FACTORY = null
> def requestInitializer = null
> def credential = null
> def builderAnalytics = new AnalyticsReporting.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
> def builderSheets = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
> def builderDrive = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
> {code}
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> /home/edited/bug25.groovy: 13: You cannot create an instance from the abstract class 'com.google.api.services.analyticsreporting.v4.AnalyticsReporting$Builder'.
>  @ line 13, column 24.
>    def builderAnalytics = new AnalyticsReporting.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
>                           ^
> /home/edited/bug25.groovy: 15: You cannot create an instance from the abstract class 'com.google.api.services.sheets.v4.Sheets$Builder'.
>  @ line 15, column 21.
>    def builderSheets = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
>                        ^
> /home/edited/bug25.groovy: 17: You cannot create an instance from the abstract class 'com.google.api.services.drive.Drive$Builder'.
>  @ line 17, column 20.
>    def builderDrive = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)