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

JShell Class.isAnonymousClass() returns wrong result

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 14, 17, 18
    • Fix Version/s: 18
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      In JShell when declaring an annonymous class directly in a new line and then calling `Class.isAnonymousClass()` erroneously returns `false`.

      However, when the result of `isAnonymousClass()` is directly used in some way (e.g. as argument for `println`) then the correct value is returned.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the statements provided below


      ---------- BEGIN SOURCE ----------
      // These erroneously print `false`:
      jshell> new Object(){}.getClass().isAnonymousClass()
      jshell> var o = new Object(){}
      jshell> o.getClass().isAnonymousClass()

      // This correctly prints `true`
      jshell> System.out.println(new Object(){}.getClass().isAnonymousClass());

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

        Attachments

          Activity

            People

            Assignee:
            jlahoda Jan Lahoda
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: