groovy
  1. groovy
  2. GROOVY-5396

Extending Abstract Java class with a Groovy class, can't see super properties.

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0-beta-1, 1.8.6
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      1

      Description

      If I have a standard gradle project setup (attached):

      build.gradle
      src/
        main/
          java/
            test/
              AbstractBase.java
              SamePackageJavaBase.java
          groovy/
            test/
              GroovyBase.groovy
              GroovyBaseWithSuper.groovy
      

      I have a single Abstract base class:

      AbstractBase.java
      package test ;
      
      public abstract class AbstractBase {
        int base ;
      
        public AbstractBase( int base ) {
          this.base = base ;
        }
      
        public abstract int mult( int n ) ;
      }
      

      And a class GroovyBase that extends this class:

      GroovyBase.groovy
      package test
      
      public class GroovyBase extends AbstractBase {
        public GroovyBase( int n ) {
          super( n )
        }
      
        public int mult( int n ) {
          n * base
        }
      
        static main( args ) {
          println new GroovyBase( 10 ).mult( 3 )
        }
      }
      

      When running this (using the Gradle script in the attachment), I get the exception:

      Exception in thread "main" groovy.lang.MissingPropertyException: No such property: base for class: test.GroovyBase
      Possible solutions: class
      

      Changing the line

          n * base
      

      to

          n * super.base
      

      Or making the base field public in the AbstractBase class makes it work.

      It's as if the classes are considered to be in different packages for some things, but not for others.

      Thinking about it, not sure if this is a Gradle bug or a Groovy cross compiler one.

      To run the tests, unpack the attachment, and run:

      # Test the above failing example
      gradle -Pmain=test.GroovyBase
      # Test the addition of super.base
      gradle -Pmain=test.GroovyBaseWithSuper
      # Test the Java extension of the Abstract class
      gradle -Pmain=test.SamePackageJavaBase
      

      You can change the groovy version from 1.8.6 by passing (for example) -Pgroovy=groovy=2.0.0-beta-2

        Activity

        No changes have yet been made on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Tim Yates
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: