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

Using a local method with :: notation in Java 8 causes index out of bounds

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.2.0
    • None
    • None

    Description

      I tried to use the toString method on an object as a map function:

                      .<String>map(Trade::toString)
      

      This caused an index out of bounds error:

      java.lang.ArrayIndexOutOfBoundsException: -1
      	at org.apache.flink.api.java.typeutils.TypeExtractor.getUnaryOperatorReturnType(TypeExtractor.java:351)
      	at org.apache.flink.api.java.typeutils.TypeExtractor.getUnaryOperatorReturnType(TypeExtractor.java:305)
      	at org.apache.flink.api.java.typeutils.TypeExtractor.getMapReturnTypes(TypeExtractor.java:120)
      	at org.apache.flink.streaming.api.datastream.DataStream.map(DataStream.java:506)
      	at com.mapr.aggregate.AggregateTest.testAggregateTrades(AggregateTest.java:81)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
      

      On the other hand, if I use a public static method, like this:

                      .<Trade>map(Trade::fromString)
      

      All is good. fromString and toString are defined like this:

          public static Trade fromString(String s) throws IOException {
              return mapper.readValue(s, Trade.class);
          }
      
          @Override
          public String toString() {
              return String.format("{\"%s\", %d, %d, %.2f}", symbol, time, volume, price);
          }
      

      This might be a viable restriction on what functions I can use, but there certainly should be a better error message, if so.

      Attachments

        Issue Links

          Activity

            People

              twalthr Timo Walther
              tdunning Ted Dunning
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: