MalformedURLException in HttpURLConnection.getResponseCode()

T

Twisted

As the Subject: says. I'm getting the odd MalformedURLException after
a) successfully constructing a URL, b) successfully obtaining a
URLConnection from it, c) successfully casting this to
HttpURLConnection, d) setting some header fields and actually invoking
connect() on it, and then, with zero exceptions having been thrown thus
far:

int rc = uc.getResponseCode();

throws.

It must be constructing new URLs under the hood. And making mistakes
sometimes.

java.net.MalformedURLException: Illegal character in URL
at sun.net.www.http.HttpClient.getURLFile(HttpClient.java:537)
at
sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:345)
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1002)
at
java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
at com.sourceforge.sphaera.SThread.spiderURL(SThread.java:344)
at com.sourceforge.sphaera.SThread.run(SThread.java:169)

Looks like Sun's bug, not mine, unless there's something else users of
java.net should be checking for that I'm not besides the obvious.

It's another strange one.
 
D

Daniel Pitts

Twisted said:
As the Subject: says. I'm getting the odd MalformedURLException after
a) successfully constructing a URL, b) successfully obtaining a
URLConnection from it, c) successfully casting this to
HttpURLConnection, d) setting some header fields and actually invoking
connect() on it, and then, with zero exceptions having been thrown thus
far:

int rc = uc.getResponseCode();

throws.

It must be constructing new URLs under the hood. And making mistakes
sometimes.

java.net.MalformedURLException: Illegal character in URL
at sun.net.www.http.HttpClient.getURLFile(HttpClient.java:537)
at
sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:345)
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1002)
at
java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
at com.sourceforge.sphaera.SThread.spiderURL(SThread.java:344)
at com.sourceforge.sphaera.SThread.run(SThread.java:169)

Looks like Sun's bug, not mine, unless there's something else users of
java.net should be checking for that I'm not besides the obvious.

It's another strange one.

Since you keep running into trouble, I would suggest you use a java 1.5
instead of 1.6. If you still have trouble, think about what YOU could
do differently. This is the third post of yours where the "library" has
a bug. With something as widely used as Java, this is highly unlikely.

If you're problem persists in Java 1.5, then it is probably *your* bug.
If it goes away, then it should be reported in Sun's bug database.

Try to create an sscce http://www.physci.org/codes/sscce/ that
recreates the problem. If you can post that here (or for any of your
other threads), we might be able to help you understand why it isn't
working. Otherwise a blind stacktrace (even with some context) isn't
going to help us help you.

Good luck,
Daniel.
 
T

Twisted

Twisted said:
As the Subject: says. I'm getting the odd MalformedURLException after
a) successfully constructing a URL, b) successfully obtaining a
URLConnection from it, c) successfully casting this to
HttpURLConnection, d) setting some header fields and actually invoking
connect() on it, and then, with zero exceptions having been thrown thus
far:

int rc = uc.getResponseCode();

throws.

It must be constructing new URLs under the hood. And making mistakes
sometimes.

java.net.MalformedURLException: Illegal character in URL
at sun.net.www.http.HttpClient.getURLFile(HttpClient.java:537)
at
sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:345)
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1002)
at
java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
at com.sourceforge.sphaera.SThread.spiderURL(SThread.java:344)
at com.sourceforge.sphaera.SThread.run(SThread.java:169)

Looks like Sun's bug, not mine, unless there's something else users of
java.net should be checking for that I'm not besides the obvious.

It's another strange one.


Does anyone have a useful response to this?

I construct an http URL -- no exception is thrown -- and open a
connection. Attempting to get the response code throws
MalformedURLException. This shouldn't be happening, as near as I can
tell.
 
D

Daniel Pitts

Twisted said:
Does anyone have a useful response to this?

I construct an http URL -- no exception is thrown -- and open a
connection. Attempting to get the response code throws
MalformedURLException. This shouldn't be happening, as near as I can
tell.

Please give us a short example that recreates the problem. Otherwise we
are operating blindly.
 
T

Twisted

Daniel said:
Please give us a short example that recreates the problem. Otherwise we
are operating blindly.

It's not reproducible except statistically, with enough random
browsing. There may be "magic" sites that set it off reliably; I don't
know. But it (and the priorityqueue npe) seem to be POM-dependent. If
you use it a lot, it will explode in your face sooner or later, but if
you just test it once it will probably behave itself.

Surely you've seen that kind of behavior before, if you've any
experience in the field of computer programming?
 
Joined
Dec 20, 2007
Messages
1
Reaction score
0
If the url string is followed by any whitespace and then some text the URL constructor does not object and a URLConnection object can be obtained with the openConnection() method. However, call getInputStream() on the connection, and you will get a belated MalformedURLException.
This is in 1.6, I've not tried earlier yet.

Code:
URL url = new URL("http://www.google.com/images/logo.gif text_after_white_space");
URLConnection con = url.openConnection();
InputStream in = con.getInputStream(); // generates error
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top