Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-5070

Unable to use Scala's BeanProperty with classes

    Details

      Description

      When using Scala class with with property (both var and val) annotated as BeanProperty, throws an exception java.lang.IllegalStateException: Detected more than one getter.

      The simple code which follows throws that exception:

      class SomeClass(@BeanProperty var prop: Int)
      
      object SampleBeanProperty {
          def main(args: Array[String]): Unit = {
              val env = StreamExecutionEnvironment.createLocalEnvironment()
      
              // Create a DataSet from a list of elements
              env.fromElements(1,2)
                  .map(new SomeClass(_))
                  .print
      
              env.execute()
          }
      }
      

      Full exception:

      Exception in thread "main" java.lang.IllegalStateException: Detected more than one setter
      	at org.apache.flink.api.java.typeutils.TypeExtractor.isValidPojoField(TypeExtractor.java:1646)
      	at org.apache.flink.api.java.typeutils.TypeExtractor.analyzePojo(TypeExtractor.java:1692)
      	at org.apache.flink.api.java.typeutils.TypeExtractor.privateGetForClass(TypeExtractor.java:1580)
      	at org.apache.flink.api.java.typeutils.TypeExtractor.privateGetForClass(TypeExtractor.java:1479)
      	at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfoWithTypeHierarchy(TypeExtractor.java:737)
      	at org.apache.flink.api.java.typeutils.TypeExtractor.privateCreateTypeInfo(TypeExtractor.java:543)
      	at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfo(TypeExtractor.java:497)
      	at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfo(TypeExtractor.java:493)
      	at SampleBeanProperty$.main(SampleBeanProperty.scala:18)
      	at SampleBeanProperty.main(SampleBeanProperty.scala)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
      

      If the class is changed into case class, code with BeanProperty works fine.

        Issue Links

          Activity

          Hide
          greghogan Greg Hogan added a comment -

          master: c90b6da5ff845e55c52150a3c6f0b7192959a40e
          release-1.3: 949d16e8a00656fa1ee1b235c8ca704331b09f55

          Show
          greghogan Greg Hogan added a comment - master: c90b6da5ff845e55c52150a3c6f0b7192959a40e release-1.3: 949d16e8a00656fa1ee1b235c8ca704331b09f55
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/flink/pull/3318

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/flink/pull/3318
          Hide
          githubbot ASF GitHub Bot added a comment -

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

          https://github.com/apache/flink/pull/3318#discussion_r101299257

          — Diff: flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java —
          @@ -1723,20 +1720,17 @@ private boolean isValidPojoField(Field f, Class<?> clazz, ArrayList<Type> typeHi
          // return type is void.
          m.getReturnType().equals(Void.TYPE)
          ) {

          • if(hasSetter) { - throw new IllegalStateException("Detected more than one setter"); - }

            hasSetter = true;
            }
            }
            if(hasGetter && hasSetter)

            { return true; }

            else {
            if(!hasGetter) {

          • LOG.debug(clazz+" does not contain a getter for field "+f.getName() );
            + LOG.info(clazz+" does not contain a getter for field "+f.getName() );
              • End diff –

          I would say yes. It is very hard for users to figure out why a object is not a POJO. Information about the problematic field is helpful. This message will occur as often as `clazz is not a valid POJO.`, so one output per non-POJO.

          Show
          githubbot ASF GitHub Bot added a comment - Github user twalthr commented on a diff in the pull request: https://github.com/apache/flink/pull/3318#discussion_r101299257 — Diff: flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java — @@ -1723,20 +1720,17 @@ private boolean isValidPojoField(Field f, Class<?> clazz, ArrayList<Type> typeHi // return type is void. m.getReturnType().equals(Void.TYPE) ) { if(hasSetter) { - throw new IllegalStateException("Detected more than one setter"); - } hasSetter = true; } } if(hasGetter && hasSetter) { return true; } else { if(!hasGetter) { LOG.debug(clazz+" does not contain a getter for field "+f.getName() ); + LOG.info(clazz+" does not contain a getter for field "+f.getName() ); End diff – I would say yes. It is very hard for users to figure out why a object is not a POJO. Information about the problematic field is helpful. This message will occur as often as `clazz is not a valid POJO.`, so one output per non-POJO.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user StephanEwen commented on the issue:

          https://github.com/apache/flink/pull/3318

          I cannot recall a reason why we allow only one getter/setter.

          I have a comment on the logging, though...

          Show
          githubbot ASF GitHub Bot added a comment - Github user StephanEwen commented on the issue: https://github.com/apache/flink/pull/3318 I cannot recall a reason why we allow only one getter/setter. I have a comment on the logging, though...
          Hide
          githubbot ASF GitHub Bot added a comment -

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

          https://github.com/apache/flink/pull/3318#discussion_r101282565

          — Diff: flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java —
          @@ -1723,20 +1720,17 @@ private boolean isValidPojoField(Field f, Class<?> clazz, ArrayList<Type> typeHi
          // return type is void.
          m.getReturnType().equals(Void.TYPE)
          ) {

          • if(hasSetter) { - throw new IllegalStateException("Detected more than one setter"); - }

            hasSetter = true;
            }
            }
            if(hasGetter && hasSetter)

            { return true; }

            else {
            if(!hasGetter) {

          • LOG.debug(clazz+" does not contain a getter for field "+f.getName() );
            + LOG.info(clazz+" does not contain a getter for field "+f.getName() );
              • End diff –

          Does it make sense to log this on `info`? That can be a lot of log output for programs with many types...

          Show
          githubbot ASF GitHub Bot added a comment - Github user StephanEwen commented on a diff in the pull request: https://github.com/apache/flink/pull/3318#discussion_r101282565 — Diff: flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java — @@ -1723,20 +1720,17 @@ private boolean isValidPojoField(Field f, Class<?> clazz, ArrayList<Type> typeHi // return type is void. m.getReturnType().equals(Void.TYPE) ) { if(hasSetter) { - throw new IllegalStateException("Detected more than one setter"); - } hasSetter = true; } } if(hasGetter && hasSetter) { return true; } else { if(!hasGetter) { LOG.debug(clazz+" does not contain a getter for field "+f.getName() ); + LOG.info(clazz+" does not contain a getter for field "+f.getName() ); End diff – Does it make sense to log this on `info`? That can be a lot of log output for programs with many types...
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user twalthr opened a pull request:

          https://github.com/apache/flink/pull/3318

          FLINK-5070 [types] Unable to use Scala's BeanProperty with classes

          This PR fixes issues with `@BeanProperty` annotation. The problem is that `var` generates Scala-style getters/setters and the annotation generates Java-style getters/setters. Right now Flink only supports one style in a POJO. I don't know why we have this restriction. I removed them.

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

          $ git pull https://github.com/twalthr/flink FLINK-5070

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

          https://github.com/apache/flink/pull/3318.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 #3318


          commit 552e708a713df6ed9fe65f508771e56b0dbcd50b
          Author: twalthr <twalthr@apache.org>
          Date: 2017-02-15T10:05:38Z

          FLINK-5070 [types] Unable to use Scala's BeanProperty with classes


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user twalthr opened a pull request: https://github.com/apache/flink/pull/3318 FLINK-5070 [types] Unable to use Scala's BeanProperty with classes This PR fixes issues with `@BeanProperty` annotation. The problem is that `var` generates Scala-style getters/setters and the annotation generates Java-style getters/setters. Right now Flink only supports one style in a POJO. I don't know why we have this restriction. I removed them. You can merge this pull request into a Git repository by running: $ git pull https://github.com/twalthr/flink FLINK-5070 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/flink/pull/3318.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 #3318 commit 552e708a713df6ed9fe65f508771e56b0dbcd50b Author: twalthr <twalthr@apache.org> Date: 2017-02-15T10:05:38Z FLINK-5070 [types] Unable to use Scala's BeanProperty with classes

            People

            • Assignee:
              twalthr Timo Walther
              Reporter:
              jsnowacki Jakub Nowacki
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development