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

boolean expression deemed illegal - but only inside of an assertion

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7
    • tools
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.6.0_20"
      OpenJDK Runtime Environment (IcedTea6 1.9.1) (6b20-1.9.1-1ubuntu3)
      OpenJDK 64-Bit Server VM (build 17.0-b16, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux notebook 2.6.35-22-generic #35-Ubuntu SMP Sat Oct 16 20:45:36 UTC 2010 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      a certain boolean expression involving generics (see code below) is deemed illegal when used inside of an assertion. When the expression is stored in a boolean variable instead, no error occurs.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Apply javac to the class given below.

      $ javac AClass.java


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      a clean compile.
      ACTUAL -
      a compilation error

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      AClass.java:18: illegal start of expression
      assert(AClass.<Integer> mk().isX());
      ^
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public abstract class AClass<N> {

      public abstract boolean isX();

      public static <K> AClass<K> mk() {
      return new AClass<K> () {
      @Override
      public boolean isX() {
      return true;
      }
      };
      }

      public static void test() {
      assert(AClass.<Integer> mk().isX());
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      public abstract class AClass<N> {

      public abstract boolean isX();

      public static <K> AClass<K> mk() {
      return new AClass<K> () {
      @Override
      public boolean isX() {
      return true;
      }
      };
      }

      public static void test() {
      boolean x = AClass.<Integer> mk().isX();
      assert x;
      }
      }

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: