Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7087329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:39:40+00:00 2026-05-28T07:39:40+00:00

EDIT: it turned out this question had been asked the wrong way — see

  • 0

EDIT: it turned out this question had been asked the wrong way — see my answer below. Please vote to close it.

For a unit test, I need to make the new java.net.URL(String) constructor throw a MalformedURLException, but it takes an awfully long time for what it does — 2.5 seconds.

I understand this is probably related to an attempt to create a protocol handler, so I tried specifying no protocol handler, e.g.:

new URL(null);
new URL("://");
new URL("/abc");

I briefly looked through the implementation, it seems to be preparsing the URL string to eliminate obvious errors. Why does it take so long, even with “null”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:39:40+00:00Added an answer on May 28, 2026 at 7:39 am

    Could it be something else causing the delay? I can’t reproduce this:

    public class UrlTest {
    
        static public void urltest(String s) {
            long start = System.currentTimeMillis();
            try {
                new URL(s);
                System.out.println("successfully created URL after "+(System.currentTimeMillis()-start)+" milliseconds. URL: "+s);
            } catch(Exception e) {
                System.out.println(e.toString()+" after "+(System.currentTimeMillis()-start)+" milliseconds. URL: "+s);         
            }
        }
    
        static public void main(String[] args) {
            System.out.println(System.getProperty("java.version"));
            urltest(null);
            urltest("://");
            urltest("/abc");
    
        }
    }
    

    Output:

    1.6.0_18-ea
    java.net.MalformedURLException after 0 milliseconds. URL: null
    java.net.MalformedURLException: no protocol: :// after 1 milliseconds. URL: ://
    java.net.MalformedURLException: no protocol: /abc after 0 milliseconds. URL: /abc
    

    Regarding equals(), this is from the javadoc:

    Two hosts are considered equivalent if both host names can be resolved into the same IP addresses; else if either host name can’t be resolved, the host names must be equal without regard to case; or both host names equal to null.

    Since hosts comparison requires name resolution, this operation is a blocking operation.

    Note: The defined behavior for equals is known to be inconsistent with virtual hosting in HTTP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: I have solved this by myself. See my answer below I have set
My question is somewhat specific, but the answer I need is general: (turned out
Edit 4: The main issue has been resolved - turned out the problem was
Following my previous question came a quick and great answer, however it turned out
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot
EDIT: This question is more about language engineering than C++ itself. I used C++
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
EDIT following resolution, this has been substantially edited to dump irrelevant detail and explain
After all the answers to my last question about fine-tuning turned out to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.