RFR (S) 8151223: String concatenation fails with implicit toString() on package-private class

Aleksey Shipilev aleksey.shipilev at oracle.com
Mon Mar 7 18:46:27 UTC 2016


Hi,

There seems to be a corner case in our current String concatenation
handling: we are recording the exact argument types to call
StringConcatFactory with, to allow JDK to use that information for
optimization. This works well, until we meet a private class. Then, we
get an IllegalAccessError while trying to execute a bootstrap method
referencing an inaccessible class:
   https://bugs.openjdk.java.net/browse/JDK-8151223

This does not happen with "old" concat flavor, because we are calling
StringBuilder.append(Object) there, which does not leak away the private
type.

Luckily, we are not mandated to always call StringConcatFactory with an
exact type. We can detect inaccessible classes during compilation, and
use the closest accessible super-type instead. We could just strip to
java.lang.Object in those cases, but it seems better to sharpen the type
to the first accessible/non-ambiguous class/interface up the hierarchy.

Webrev:
   http://cr.openjdk.java.net/~shade/8151223/webrev.01

Testing: failing test, new regression test; JDK java/lang/String;
Langtools com/,jdk/,tools/

Thanks,
-Aleksey

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20160307/1431ba55/signature.asc>


More information about the compiler-dev mailing list