Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6548436

Incorrect inconvertible types error

    Details

    • Subcomponent:
    • Resolved In Build:
      b40
    • CPU:
      generic, x86
    • OS:
      generic, linux, windows_xp
    • Verification:
      Not verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.6.0"
        Java(TM) SE Runtime Environment (build 1.6.0-b105)
        Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)


        ADDITIONAL OS VERSION INFORMATION :
        Linux lotp-laptop 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686 GNU

        A DESCRIPTION OF THE PROBLEM :
        In some cases javac outputs errors about inconvertible types. The circumstances in which this happens seem to be rather complicated. Trying to reduce the problem to a canonical form eradicates it.

        Full discussion can be found at http://forum.java.sun.com/thread.jspa?threadID=5162196&tstart=0

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Try to compile the supplied source code example.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Should compile without errors
        ACTUAL -
        javac outputs the following errors:

        javac Bug.java
          Bug.java:27: inconvertible types
        found : JETEvent<capture#608 of ?>
        required: FSDEvent
                        if(event == null || ! (event instanceof FSDEvent)) { // <-- doesn't compile
                                               ^
          Bug.java:30: inconvertible types
        found : JETEvent<capture#870 of ?>
        required: FSDEvent
                        FSDEvent fsdEvent = (FSDEvent)event;
                                                      ^
        2 errors

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------

        abstract class JETEvent<E extends Enum<E>> {}
         
        class FSDEvent extends JETEvent<FSDEvent.SUBTYPE> {
            public enum SUBTYPE {
        TYPE_A,
        TYPE_B
            }
        }
         
        interface State<T extends Task> {
            public Transition<T> getTransition(JETEvent<?> event);
        }
         
        class DefaultState<T extends Task> implements State<T> {
            public Transition<T> getTransition(JETEvent<?> event) {
             return null;
            }
        }
         
        class FSDState extends DefaultState<FSDTask> {
        @Override
        public FSDTransition getTransition(JETEvent<?> event) {
        if(event == null || ! (event instanceof FSDEvent)) { // <-- doesn't compile
        return null;
        }
        FSDEvent fsdEvent = (FSDEvent)event; // <-- doesn't compile either
        return null;
                }
        }
         
        interface Task<T extends Task> {}
         
        class FSDTask extends DefaultTask<FSDTask> {}
         
        class DefaultTask<T extends DefaultTask> implements Task<T> {}
         
        interface Transition<T extends Task> {}
         
        class DefaultTransition<T extends Task> implements Transition<T> {}
         
        class FSDTransition extends DefaultTransition<FSDTask> {}
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Casting to Object first solves the problem. The two problematic lines must be

        if(event == null || ! ((Object)event instanceof FSDEvent)) { // <-- This compiles
        FSDEvent fsdEvent = (FSDEvent)(Object)event; // <-- This now also compiles

        for the compilation to work

        Release Regression From : 5.0u11
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

        Release Regression From : 5.0u11
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  mcimadamore Maurizio Cimadamore
                  Reporter:
                  ndcosta Nelson Dcosta (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: