RFR: 8215990: Avoid using reflection to create common default URLStreamHandlers
Alan Bateman
Alan.Bateman at oracle.com
Wed Jan 2 14:06:18 UTC 2019
On 02/01/2019 10:43, Claes Redestad wrote:
> :
>
>>
>> While we're in the area then it would be nice to eliminate the use of
>> Class::newInstance too - if each of the built-in protocol handlers is
>> public with a public no-arg constructor then
>> getConstructor().newInstance() should do it.
>
> To be perfectly compatible I think
> .getDeclaredConstructor().newInstance() should be used:
>
> http://cr.openjdk.java.net/~redestad/8215990/jdk.01
This looks okay. Using getConstructor should work here too because this
is the built-in protocol handlers. I think the only compatibility
concern with getConstructor in this code path would be if someone
deploys a custom protocol handler in the sun.net.* tree via
-Xbootclasspath/p or by patches a java.* or jdk.* module that is mapped
to the boot loader and the protocol handler doesn't have a public no-arg
constructor. If they set java.protocol.handlers.pkgs property then it
uses lookupViaProperty and Class::newInstance as before.
-Alan
More information about the net-dev
mailing list