2

Not all invalid urls will be consider as invalid by java.net.URL/URI

An example: http:www.google.com

Is it a bug or is it a feature?

Or is maybe the string above a valid url?

3
  • That's not a valid URI. Perhaps you mean http://www.google.com. Commented Jul 27, 2018 at 8:03
  • 1
    If you paste that on the browser it works , and transforms it to google.com , maybe there is a similar functionality Commented Jul 27, 2018 at 8:05
  • No, I mean http:www.google.com. And yes, I know. it is an invalid URI, but it can be parsed by both java.net.URL and java.net.URI Commented Jul 27, 2018 at 8:05

1 Answer 1

2

Without //, the URL is treated as a relative URL, that needs a context to be useful.

If you try using it, you'll get this error:

IllegalArgumentException: protocol = http host = null
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for explanation. I'm now using the java.net.URL to check if the given URL is valid in general and then check if it has host or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.