Proposal: #ClassLoaderNames

Mark Reinhold mark.reinhold at oracle.com
Mon Sep 12 15:12:01 UTC 2016


Issue summary
-------------

  #ClassLoaderNames --- Enhance class loaders to have optional names, so
  that external module systems can provide better diagnostics.  When the
  run-time system generates a stack trace or an exception message that
  mentions a module name and version, if present, then it should also
  insert the name of that module's class loader, if present. [1]

Proposal
--------

Add a string-returning `getName()` method to `java.lang.ClassLoader`
along with a new constructor with which the name can be specified.  If a
name is not specified when a class loader is created then it will have no
name, i.e., the `getName` method will return `null`.  Add corresponding
constructors to `java.net.URLClassLoader` and
`java.security.SecureClassLoader`.

Extend `java.lang.StackTraceElement` so that a stack-trace element can
include the name of the relevant class loader, and revise its `toString`
method to convey that name when present.

Arrange for the built-in platform and application class loaders to have
the names `"platform"` and `"app"`, respectively.  (The bootstrap class
loader cannot be given a name since it is not reified as a `ClassLoader`
object.)


[1] http://openjdk.java.net/projects/jigsaw/spec/issues/#ClassLoaderNames


More information about the jpms-spec-experts mailing list