thread "main" java.lang.Error: factory already defined

Posted on 2006-05-08
Last Modified: 2008-01-09
I Have created a Java program in which i am calling  the function
url.setURLStreamHandlerFactory(hh); i get the following error.
thread "main" java.lang.Error: factory already defined.

Can someone please suggest as to why the error is coming & how to resolve the same ?

Question by:vikrant_kpr
    LVL 6

    Expert Comment

    can u post the code?
    LVL 14

    Accepted Solution

    looking at the source code of
    you'll find that this error will be thrown when factory is already defined (factory != null)

    public static void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) {
          synchronized (streamHandlerLock) {
                if (factory != null) {
                      throw new Error("factory already defined");
                SecurityManager security = System.getSecurityManager();
                if (security != null) {
                factory = fac;

    due to the java documentation:
    This method can be called at most once in a given Java Virtual Machine.
    because factory is a Class member (not instance member) declared as: static URLStreamHandlerFactory factory

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This article will show, step by step, how to integrate R code into a R Sweave document
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now