2

I'm trying to compile following code with Maven:

  final Table<Integer, Integer, Integer> destination = HashBasedTable.create();
  final Map<Integer, Integer> source = new HashMap<>();

  // compiles
  final Table<Integer, Integer, Integer> broker =
           source.entrySet().stream().collect( Tables.toTable( e -> 0, e -> 0, e -> 0,
                    ( e1, e2 ) -> 0, HashBasedTable::create ) );
  destination.putAll( broker );

  // doesn't compile
  destination.putAll( source.entrySet().stream().collect( Tables.toTable( e -> 0, e -> 0,
           e -> 0, ( e1, e2 ) -> 0, HashBasedTable::create ) ) );

the result is error:

incompatible types: inferred type does not conform to upper bound(s)
inferred: com.google.common.collect.Table<java.lang.Object,java.lang.Object,java.lang.Object>
upper bound(s): com.google.common.collect.Table<java.lang.Object,java.lang.Object,java.lang.Object>,com.google.common.collect.Table<? extends java.lang.Integer,? extends java.lang.Integer,? extends java.lang.Integer>,java.lang.Object

Why do I need this broker table to compile? The most interesting thing is that somehow Eclipse compiler knows how to deal with it.

I'm using Maven compiler plugin version 3.8.0 with target and source tags set to 1.8.

I feel like it something is wrong in the workflow here - I'm developing in IDE, everything looks fine, and than all of the sudden it turns out that there is something wrong with my code and it does not even compile on Maven build.

I tried on the newest 3.6 Maven version, and Eclipse compiler comes from Eclipse 2018-12, both Java 8 and 11.

Line
  • 1,529
  • 3
  • 18
  • 42
  • 1
    How did u configure maven-compiler-plugin in your pom.xml – HRgiger Feb 18 '19 at 12:34
  • The Eclipse compiler allows you to compile invalid code by making the failure manifest at runtime (rather than compile-time). When trying to run invalid code compiled with the Eclipse compiler some error will be thrown. When you run the specified code do you get such an error? – Slaw Feb 18 '19 at 12:34
  • 1
    @HRgiger I included relevant info in the question. – Line Feb 18 '19 at 12:36
  • @Slaw no, everything works fine. I added the link to Bitbucket, from where you can clone the project and check yourself. – Line Feb 18 '19 at 12:38
  • It looks like return type error,debug what it returning – Dhanraj Feb 18 '19 at 12:49
  • @DhanrajTijare `System.out.println( source.entrySet().stream().collect( Tables.toTable( e -> 0, e -> 0, e -> 0, ( e1, e2 ) -> 0, HashBasedTable::create ) ) );` shows that the returned type is HashBasedTable, just like I expect. – Line Feb 18 '19 at 12:52
  • 1
    Maven uses `javac` whereas Eclipse has its own compiler. [Here is a similar issue (generic parameter types with bounds) where IMHO Eclipse is right](https://stackoverflow.com/a/45801092/6505250). Which JDK exactly is used in the Maven build? Oracle JDK 11.0.2? – howlger Feb 18 '19 at 13:22
  • @howlger yes, I also checked on 1.8.0_202 - it's the same – Line Feb 18 '19 at 13:44
  • 2
    @Line If it fails also with the Oracle JDK 11.0.2, make sure the issue is known by Oracle. As workaround avoid this in your code or use the Eclipse compiler in your Maven build. – howlger Feb 18 '19 at 14:08

1 Answers1

0

I filled a bug concerning this, and it seems to be proceeded: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8219318.

Line
  • 1,529
  • 3
  • 18
  • 42