OpenJDK compiler 6b20pre on Maverick doesn't recognize Generics Correctly

Bug #611284 reported by Lorenzo Zoffoli on 2010-07-29
This bug affects 2 people
Affects Status Importance Assigned to Milestone
openjdk-6 (Ubuntu)

Bug Description

OpenJDK compiler can't unify custom type defined in signature by generics.


import java.util.List;
public class GenericBug {
    public <X extends String, Y extends List<X>, Z extends List<X>> Z add(X element, Y list){
        return list;

This code compile correctly on Sun JDK but OpenJDK compiler displays error:
"incompatible types
required: Z
found: Y"
But btw Z and Y is the same type: List<X>

description: updated
description: updated
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in openjdk-6 (Ubuntu):
status: New → Confirmed
Dmitry (dmitry-korolyov) wrote :

// The following code does not compile under openjdk-6, while it compiles under openjdk-7 and sun-jdk-6

// Error message:
//[10,14] invalid inferred types for K,V; inferred type does not conform to declared bound(s)
// inferred: C
// bound(s): java.lang.String

// java -version
// java version "1.6.0_23"
// OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10)
// OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

// uname -srvmpio
// Linux 3.0.0-15-generic #24-Ubuntu SMP Mon Dec 12 15:23:55 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

import javax.annotation.Nullable;
import java.util.Comparator;
import java.util.TreeMap;

public class Test {
  public static void main(String[] args) {

  public static <C, K extends C, V> TreeMap<K, V> newTreeMap(
      @Nullable Comparator<C> comparator) {
    // Ideally, the extra type parameter "C" shouldn't be necessary. It is a
    // work-around of a compiler type inference quirk that prevents the
    // following code from being compiled:
    // Comparator<Class<?>> comparator = null;
    // Map<Class<? extends Throwable>, String> map = newTreeMap(comparator);
    return new TreeMap<K, V>(comparator);

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers