[OpenJDK 2D-Dev] jdk6 and jdk7: wrong class cast in sun.print.IPPPrintService (in Solaris classes)
Jennifer Godinez
jennifer.godinez at oracle.com
Tue Nov 16 17:29:49 UTC 2010
Hi Nico,
In our code we only use http in getIPPConnection so we expect
HttpURLConnection . If openConection is returning FileURLConnection
then this looks like a bug and needs further investigation. Please
file the bug at:
http://bugreport.sun.com/bugreport/
Thank you.
Jennifer
Nico R. wrote:
> Hello!
>
> In sun.print.IPPPrintService.getIPPConnection(URL), there is a bug with
> class casting: see
>
>
> <URL:http://hg.openjdk.java.net/jdk6/jdk6/jdk/file/5672a2be515a/src/solaris/classes/sun/print/IPPPrintService.java>,
> lines 1556–1565 for JDK 6,
>
> and
>
>
> <URL:http://hg.openjdk.java.net/jdk7/swing/jdk/file/d449b91c56b6/src/solaris/classes/sun/print/IPPPrintService.java>,
> lines 1563–1572 for JDK 7.
>
> The buggy code is:
>
> public static HttpURLConnection getIPPConnection(URL url) {
> HttpURLConnection connection;
> try {
> connection = (HttpURLConnection)url.openConnection();
> } catch (java.io.IOException ioe) {
> return null;
> }
> if (!(connection instanceof HttpURLConnection)) {
> return null;
> }
>
> If the call to openConnection returns a FileURLConnection (as it does on
> my system), that cannot be cast to an HttpURLConnection. The instanceof
> check happens too late in the code.
>
> What to do: either
> * catch a ClassCastException and return null from the catch block, or
> * use a variable of type URLConnection to store the result from
> openConnection(), and cast it to HttpURLConnection /after/ the block
> with the instanceof check.
>
> The problem occurs, because there are URLs like "file:/dev/null" in the
> list or URLs to try. They are retrieved from
> sun.print.CUPSPrinter.getAllPrinters() via
> sun.print.UnixPrintServiceLookup.refreshServices().
>
> I assume this happens for printers that were auto-detected (e.g. via
> ZeroConf etc.) some time ago, but are not accessible at the moment), but
> I am not sure about that.
>
> Perhaps the CUPS system is improperly configured, but this should not
> cause Java applications to throw ClassCastExceptions.
>
> Regards
>
More information about the 2d-dev
mailing list