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

Javac accepts erroneous binary comparison operations

    XMLWordPrintable

Details

    • b98
    • Verified

    Description

      This code should not compile:

      class Main {
      public boolean func(Object obj) {
      return obj == 0;
      }
      }

      But javac (since JDK 7 accepts it).

      The following variant:

      class Main {
      public boolean func(Object obj) {
      return 0 == obj;
      }
      }

      should also not compile - but note that this was accepted since JDK 5.

      Relevant JLS section is 15.21. Javac seems to treat this as a reference comparison, but a reference comparison is only allowed when BOTH operands are reference types.

      Attachments

        Issue Links

          Activity

            People

              emc Eric Mccorkle
              mcimadamore Maurizio Cimadamore
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: