groovy
  1. groovy
  2. GROOVY-4902

Groovy class not compatible with Java integration when @Immutable is used

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.8.1, 1.7.11
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      0

      Description

      The following Groovy class with the UsePerson.java below works well:

      class Person {
        String firstName
        public Person(first) { firstName = first }
      }
      

      Defining a class with @Immutable annotation seems to result in compilation error when used from Java.

      Person.groovy
      @Immutable class Person {
        String firstName
      }
      
      UsePerson.java
      public class UsePerson {
        public static void main(String[] args) {
          Person person = new Person("Sam");
          System.out.println(person.getFirstName());
        }
      }
      
      >groovyc Person.groovy
      
      >ls
      Person.class	Person.groovy	UsePerson.java
      
      >javac UsePerson.java 
      UsePerson.java:3: cannot access Person
      bad class file: ./Person.class
      undeclared type variable: K
      Please remove or make sure it appears in the correct subdirectory of the classpath.
          Person person = new Person("Sam");
          ^
      1 error
      

        Activity

        Hide
        Paul King added a comment -

        add code tags

        Show
        Paul King added a comment - add code tags
        Paul King made changes -
        Field Original Value New Value
        Description The following Groovy class with the UsePerson.java below works well:

        class Person {
          String firstName
          
          public Person(first) { firstName = first }
        }

        Defining a class with @Immutable annotation seems to result in compilation
        error when used from Java.

        //Person.groovy
        @Immutable class Person {
          String firstName
        }

        //UsePerson.java
        public class UsePerson {
          public static void main(String[] args) {
            Person person = new Person("Sam");
            System.out.println(person.getFirstName());
          }
        }

        >groovyc Person.groovy

        >ls
        Person.class Person.groovy UsePerson.java

        >javac UsePerson.java
        UsePerson.java:3: cannot access Person
        bad class file: ./Person.class
        undeclared type variable: K
        Please remove or make sure it appears in the correct subdirectory of the classpath.
            Person person = new Person("Sam");
            ^
        1 error
        The following Groovy class with the {{UsePerson.java}} below works well:
        {code}
        class Person {
          String firstName
          public Person(first) { firstName = first }
        }
        {code}
        Defining a class with @Immutable annotation seems to result in compilation error when used from Java.

        {code|title=Person.groovy}
        @Immutable class Person {
          String firstName
        }
        {code}
        {code|title=UsePerson.java}
        public class UsePerson {
          public static void main(String[] args) {
            Person person = new Person("Sam");
            System.out.println(person.getFirstName());
          }
        }
        {code}
        {noformat}
        >groovyc Person.groovy

        >ls
        Person.class Person.groovy UsePerson.java

        >javac UsePerson.java
        UsePerson.java:3: cannot access Person
        bad class file: ./Person.class
        undeclared type variable: K
        Please remove or make sure it appears in the correct subdirectory of the classpath.
            Person person = new Person("Sam");
            ^
        1 error
        {noformat}
        Paul King made changes -
        Description The following Groovy class with the {{UsePerson.java}} below works well:
        {code}
        class Person {
          String firstName
          public Person(first) { firstName = first }
        }
        {code}
        Defining a class with @Immutable annotation seems to result in compilation error when used from Java.

        {code|title=Person.groovy}
        @Immutable class Person {
          String firstName
        }
        {code}
        {code|title=UsePerson.java}
        public class UsePerson {
          public static void main(String[] args) {
            Person person = new Person("Sam");
            System.out.println(person.getFirstName());
          }
        }
        {code}
        {noformat}
        >groovyc Person.groovy

        >ls
        Person.class Person.groovy UsePerson.java

        >javac UsePerson.java
        UsePerson.java:3: cannot access Person
        bad class file: ./Person.class
        undeclared type variable: K
        Please remove or make sure it appears in the correct subdirectory of the classpath.
            Person person = new Person("Sam");
            ^
        1 error
        {noformat}
        The following Groovy class with the {{UsePerson.java}} below works well:
        {code}
        class Person {
          String firstName
          public Person(first) { firstName = first }
        }
        {code}
        Defining a class with @Immutable annotation seems to result in compilation error when used from Java.

        {code:title=Person.groovy}
        @Immutable class Person {
          String firstName
        }
        {code}
        {code:title=UsePerson.java}
        public class UsePerson {
          public static void main(String[] args) {
            Person person = new Person("Sam");
            System.out.println(person.getFirstName());
          }
        }
        {code}
        {noformat}
        >groovyc Person.groovy

        >ls
        Person.class Person.groovy UsePerson.java

        >javac UsePerson.java
        UsePerson.java:3: cannot access Person
        bad class file: ./Person.class
        undeclared type variable: K
        Please remove or make sure it appears in the correct subdirectory of the classpath.
            Person person = new Person("Sam");
            ^
        1 error
        {noformat}
        Hide
        Paul King added a comment -

        Thanks for spotting that - some internal generics information was leaking into the bytecode.

        Show
        Paul King added a comment - Thanks for spotting that - some internal generics information was leaking into the bytecode.
        Paul King made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Paul King [ paulk ]
        Fix Version/s 1.7.11 [ 17244 ]
        Fix Version/s 1.8.1 [ 17223 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Paul King
            Reporter:
            Venkat Subramaniam
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: