JDK-8144931 : Assert class signatures are correct and refer to valid classes
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 9
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2015-12-08
  • Updated: 2016-02-26
  • Resolved: 2016-02-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b107Fixed
Related Reports
Relates :  
Description
Code in java lang invoke uses strings for explicit class signatures, for example in InvokerBytecodeGenerator.java:

    /**
     * Generate an invoker method for the passed {@link LambdaForm}.
     */
    private byte[] generateCustomizedCodeBytes() {
        classFilePrologue();

        // Suppress this method in backtraces displayed to the user.
        mv.visitAnnotation("Ljava/lang/invoke/LambdaForm$Hidden;", true);

        // Mark this method as a compiled LambdaForm
        mv.visitAnnotation("Ljava/lang/invoke/LambdaForm$Compiled;", true);

        if (lambdaForm.forceInline) {
            // Force inlining of this invoker method.
            mv.visitAnnotation("Ljava/lang/invoke/ForceInline;", true);
        } else {
            mv.visitAnnotation("Ljava/lang/invoke/DontInline;", true);
        }

It would be better to express as constants, that are possibly derived from the actual class (or at least equality-based assertions performed on the string to that derived from the class).

Any such work should ideally wait until JDK-8144223 is integrated into the appropriate repo, since that updates some class signatures (e.g. some of those in the above code snippet)
Comments
http://cr.openjdk.java.net/~srastogi/8144931/webrev.01/
18-02-2016

Maybe use this pattern, to avoid linkage in product mode: static String className(String cn) { assert(checkClassName(String cn)); return cn; }
08-12-2015

If done using some naive public utility method, say, ClassSignatures.getSignatureFor(Class<?> class), I guess we could transform it to a constant expression by a jlink plugin at link time: no eager class loading and no assertions strictly required.
08-12-2015