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

Add a way to make an ObjectName without having to catch MalformedObjectNameException

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 6
    • Fix Version/s: 7
    • Component/s: core-svc
    • Labels:
      None

      Description

      When you need to make an instance of ObjectName, you can use a constructor or you can use one of its static factory methods, but in all cases you must catch MalformedObjectNameException, which is a checked exception. This is a pain, especially when initializing fields. For example, you can't do this:

          private static final ObjectName MY_NAME = new ObjectName("a:b=c");

      Instead you have to do this:

          private static final ObjectName MY_NAME;
          static {
              try {
                  MY_NAME = new ObjectName("a:b=c");
              } catch (MalformedObjectNameException e) {
                  throw new IllegalArgumentException(e);
              }
          }

      In practice, if you need to do this sort of thing a lot, you'll define a utility method that encapsulates the construction and the try/catch. Such a method (or set of overloaded methods) should be part of the API.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                emcmanus Eamonn McManus
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: