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

Conditional operator misinterprets/mixes up access modifiers for polymorph

    Details

    • Subcomponent:
    • Introduced In Version:
      5.0
    • CPU:
      x86
    • OS:
      windows_nt

      Description


      Name: jl125535 Date: 07/28/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows NT Version 4.0

      A DESCRIPTION OF THE PROBLEM :
      If I modify this sample source by relaxing X#hello's access to "package
      private", the 2 lines marked as "Never OK" will pass. Nevertheless, the
      compiler keeps rejecting my conditional expression.

      I have to admit that expecting to access X's "private" member(s) through
      its subtypes is indeed incorrect. However, I still can't figure out why
      the "package private" member(s) are missing (all classes reside in the
      same compilation unit which implies the same package). According to the
      JLS, the members with default access are subject to inheritance.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the updated sample code.

      EXPECTED BEHAVIOR :
      The compile should succeed with 3 looser modifiers ("public", "protected", "package private") and fail only with the
      strictest one ("private"). Currently this isn't so.

      ACTUAL BEHAVIOR :
      Test.java:7: cannot find symbol
      symbol: method hello()
                      (flag ? new A() : new B()).hello();
                      ^
      1 error

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Test {

      public void test(boolean flag){
      new X().hello(); // Always OK
      new A().hello();
      new B().hello();
      (flag ? new A() : new B()).hello();
      }

      static class X {
      void hello(){}
      }

      static class A extends X implements Runnable {
      public void run(){}
      }

      static class B extends X implements Runnable {
      public void run(){}
      }
      }
      ---------- END SOURCE ----------
      (Incident Review ID: 290026)
      ======================================================================
      ###@###.### 2005-03-07 18:45:14 GMT

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ahe Peter Ahe
                Reporter:
                jleesunw Jon Lee (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: