2525
2626package com .sun .tools .javac .comp ;
2727
28+ import com .sun .tools .javac .code .Types .SignatureGenerator .InvalidSignatureException ;
29+ import com .sun .tools .javac .resources .CompilerProperties .Errors ;
30+ import com .sun .tools .javac .resources .CompilerProperties .Fragments ;
2831import com .sun .tools .javac .tree .*;
2932import com .sun .tools .javac .tree .JCTree .*;
3033import com .sun .tools .javac .tree .JCTree .JCMemberReference .ReferenceKind ;
@@ -2030,7 +2033,7 @@ private String serializedLambdaDisambiguation() {
20302033 owner .type != null ||
20312034 directlyEnclosingLambda () != null );
20322035 if (owner .type != null ) {
2033- buf .append (typeSig (owner .type ));
2036+ buf .append (typeSig (owner .type , true ));
20342037 buf .append (":" );
20352038 }
20362039
@@ -2046,7 +2049,7 @@ private String serializedLambdaDisambiguation() {
20462049 //add captured locals info: type, name, order
20472050 for (Symbol fv : getSymbolMap (CAPTURED_VAR ).keySet ()) {
20482051 if (fv != self ) {
2049- buf .append (typeSig (fv .type ));
2052+ buf .append (typeSig (fv .type , true ));
20502053 buf .append (" " );
20512054 buf .append (fv .flatName ());
20522055 buf .append ("," );
@@ -2435,15 +2438,31 @@ boolean propagateAnnotations() {
24352438 */
24362439
24372440 private String typeSig (Type type ) {
2438- L2MSignatureGenerator sg = new L2MSignatureGenerator ();
2439- sg .assembleSig (type );
2440- return sg .toString ();
2441+ return typeSig (type , false );
2442+ }
2443+
2444+ private String typeSig (Type type , boolean allowIllegalSignature ) {
2445+ try {
2446+ L2MSignatureGenerator sg = new L2MSignatureGenerator (allowIllegalSignature );
2447+ sg .assembleSig (type );
2448+ return sg .toString ();
2449+ } catch (InvalidSignatureException ex ) {
2450+ Symbol c = attrEnv .enclClass .sym ;
2451+ log .error (Errors .CannotGenerateClass (c , Fragments .IllegalSignature (c , ex .type ())));
2452+ return "<ERRONEOUS>" ;
2453+ }
24412454 }
24422455
24432456 private String classSig (Type type ) {
2444- L2MSignatureGenerator sg = new L2MSignatureGenerator ();
2445- sg .assembleClassSig (type );
2446- return sg .toString ();
2457+ try {
2458+ L2MSignatureGenerator sg = new L2MSignatureGenerator (false );
2459+ sg .assembleClassSig (type );
2460+ return sg .toString ();
2461+ } catch (InvalidSignatureException ex ) {
2462+ Symbol c = attrEnv .enclClass .sym ;
2463+ log .error (Errors .CannotGenerateClass (c , Fragments .IllegalSignature (c , ex .type ())));
2464+ return "<ERRONEOUS>" ;
2465+ }
24472466 }
24482467
24492468 /**
@@ -2456,8 +2475,22 @@ private class L2MSignatureGenerator extends Types.SignatureGenerator {
24562475 */
24572476 StringBuilder sb = new StringBuilder ();
24582477
2459- L2MSignatureGenerator () {
2478+ /**
2479+ * Are signatures incompatible with JVM spec allowed?
2480+ * Used by {@link LambdaTranslationContext#serializedLambdaDisambiguation()}.
2481+ */
2482+ boolean allowIllegalSignatures ;
2483+
2484+ L2MSignatureGenerator (boolean allowIllegalSignatures ) {
24602485 super (types );
2486+ this .allowIllegalSignatures = allowIllegalSignatures ;
2487+ }
2488+
2489+ @ Override
2490+ protected void reportIllegalSignature (Type t ) {
2491+ if (!allowIllegalSignatures ) {
2492+ super .reportIllegalSignature (t );
2493+ }
24612494 }
24622495
24632496 @ Override
0 commit comments