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

(coll) Direct uninformed users away from Vector/Hashtable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 7
    • 6
    • core-libs
    • b25
    • x86
    • windows_xp
    • Not verified

      A DESCRIPTION OF THE REQUEST :
      Every single new user of the Java language that I have encountered uses the Vector and Hashtable classes, for no good reason other than they are familiar with the names and not aware of the preferred classes (List/ArrayList, Map/HashMap).

      Please (PLEASE!) at least modify the JavaDocs for these classes to add highly visible text (preferably bright red and 40pt) to direct new users to the appropriate classes, unless they REALLY want the synchronization behavior. And even then they should be directed to either the Collections.synchronizedXX wrapper methods, or the various vastly superior alternatives in "java.util.concurrent".

      JUSTIFICATION :
      It may be the case that Sun's JVM implementations are good at eliding unnecessary locking, but this assumption may not be true of other VMs. And regardless, there's just no reason to be even risking unnecessary synchronization when the only reason it is incurred is because the programmer is clueless.

      There's even an outside chance that this is a deadlock risk if someone uses the Vector/Hashtable intrinsic monitor lock, not realizing that it might conflict with the internal implementation of those classes.

      I see that an RFE to deprecate these classes has already been rejected, so while I firmly disagree with that rejection, I'll take a different approach to suggesting that this problem be addressed in some way.

      (A final observation, even several moderately experienced Java programmers I have encountered were also unaware of the synchronization behavior, and pseudo-deprecation, of these classes.)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
        Programmers, especially those new to Java, will use the List and Map classes for the traditional "vector" and "hashtable" type functionality when they don't require synchronization, and thus *guarantee* that code that doesn't require the synchronization won't ever incur any penalties on any platform/JVM implementation.

      Even better, if they actually do want synchronization, use the superior options in "java.util.concurrent", or at a minimum, *still* use the List and Map classes and use the Collections synchronization wrappers.

      Documentation that directs users to the better alternatives, both synchronized and not, that completely eliminate any need or justification for retaining/using the Vector and Hashtable classes.
      ACTUAL -
      Javadoc documentation that does not indicate that there are better alternatives to Vector and Hashtable, for any possible use of those classes.

      Lots of code that makes use of these outdated classes with unnecessary synchronization (and an inefficient synchronization implementation even when it is).

            martin Martin Buchholz
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: