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

java.lang.Thread.getId() should be final

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The method
          public long getId(); introduced in Java 5 should probably be final (in the same way as e.g. getName() is final)

      Since the javadoc says that the ID should remain unchanged:

          /**
           * Returns the identifier of this Thread. The thread ID is a positive
           * <tt>long</tt> number generated when this thread was created.
           * The thread ID is unique and remains unchanged during its lifetime.
           * When a thread is terminated, this thread ID may be reused.
           *
           * @return this thread's ID.
           * @since 1.5
           */


      , making this method final would enforce the contract.

      Our use case is that we have a subclass of Thread that defined exactly this method in JDK 1.4 already, so that now we override this method and break the contract without even noticing at compile time.
      A final method would have signaled the bug at compile time already.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Define a subclass of java.lang.Thread and override getId() with a nonsense implementation

      public long getId() {
        return new Random(System.currentTimeMillis()).nextLong();
      }


      REPRODUCIBILITY :
      This bug can be reproduced occasionally.

        Attachments

          Activity

            People

            • Assignee:
              psoper Pete Soper (Inactive)
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: