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

Provide a way to construct an ObjectName without checked exceptions

    Details

    • Subcomponent:
    • Introduced In Version:
      5.0
    • Resolved In Build:
      b37
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      All of the constructors of ObjectName and all of the static ObjectName.getInstance factory methods are declared to throw MalformedObjectNameException, which is a checked exception. This is very irritating, because it means you can't write for example:

      public class Whatever {
          private static final ObjectName mbeanName = new ObjectName("d:type=Foo");
          ...
      }

      You have to write the much more verbose:

      public class Whatever {
          private static final ObjectName mbeanName;
          static {
              try {
                  mbeanName = new ObjectName("d:type=Foo");
              } catch (MalformedObjectNameException e) {
                  throw new AssertionError(e);
              }
          }
          ...
      }

      Most people who run into this problem probably define their own factory method that does what the static{} block in the second example does:

          private static final ObjectName mbeanName = Util.newObjectName("d:type=Foo");

      but it's stupid that they should have to.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: