Re: [jnc-users] NullPointerException in HTTPUrlConnection
Status: Beta
Brought to you by:
soapy
From: Marco T. <ma...@mt...> - 2008-07-15 14:24:24
|
Hello André André 'streeto' Amorim wrote: > Hi, I just had the same problem Avi Cohen reported a couple months ago. > Using a url that does not exist leads to a NPE. The code I used for > testing is almost the same: > > import java.net.URL; > import java.net.URLConnection; > > public class URLConnectionTest { > static public void main(String[] args) { > try { > URL u = new URL("http://www.hasdklashdklj.com/"); > System.out.println(u); > URLConnection c = u.openConnection(); > System.out.println(c); > c.connect(); > System.out.println("done"); > } catch (Exception e) { > System.out.println("nono"); > e.printStackTrace(); > } > } > } > > Here's the setup: > > JNC-1.1.1 > gcc-122233 > Using Windows XP > Compiling for Windows > Compiling from source > Config: > Not excluding JCE > Not optimizing > Not stripping > Not packing > All the other options are the default (new project) > > Here's the output: > > A. exclude JCE, add GNU regex > > http://www.hasdklashdklj.com/ > nono > java.lang.NullPointerException > at > java.net.URLConnection.toString(/usr/local/src/gcc/libjava/classpath/java/net/URLConnection.java:627) > at > java.io.PrintStream.println(/usr/local/src/gcc/libjava/java/io/PrintStream.java:473) > at URLConnectionTest.main(C:/DOCUME~1/andre/CONFIG~1/Temp/ccOsbaaa.jar:0) > > > B. not excluding JCE, not adding GNU regex (does not seem to interfer, > tried with and without) > > http://www.hasdklashdklj.com/ > gnu.java.net.protocol.http.HTTPURLConnection:http://www.hasdklashdklj.com/ > nono > java.lang.NullPointerException > <<No stacktrace available>> > > > The output in eclipse is > > http://www.hasdklashdklj.com/ > sun.net.www.protocol.http.HttpURLConnection:http://www.hasdklashdklj.com/ > nono > java.net.UnknownHostException: www.hasdklashdklj.com > <http://www.hasdklashdklj.com> > at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177) > (...) > > > Anybody has a workaround? I can't find a way to check the URL without > using URL.openConnection(). maybe: try { ... } catch(NullPointerException ex) { /* illegal url */ } ? Marco > []s > > André. > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > javaCompiler-users mailing list > jav...@li... > https://lists.sourceforge.net/lists/listinfo/javacompiler-users |