title: Can not create initial context in java program
body: <pre><code>public static void setupInitialContext() {
      try {
          System.out.println("Loading Initial Context");
          NamingManager.setInitialContextFactoryBuilder(new InitialContextFactoryBuilder() {
  
              @Override
              public InitialContextFactory createInitialContextFactory(Hashtable&lt;?, ?&gt; environment)
                      throws NamingException {
                  return new InitialContextFactory() {
                      @Override
                      public Context getInitialContext(Hashtable&lt;?, ?&gt; environment) throws NamingException {
                          InitialContext context = null;
  
                          try {
                              context = new MockLocalContext();
                          } catch (Exception ex) {
                              ex.printStackTrace();
                          }
  
                          return context;
                      }
  
                  };
              }
  
          });
          System.out.println("Loaded Initial Context");
      } catch (NamingException ne) {
          ne.printStackTrace();
      }
  }
  
      public static void main(String[] args) throws NamingException {
      setupInitialContext();
      InitialContext context = new InitialContext();
      context.lookup(DS_ORACLE);
  }
  </code></pre>
  
  <p><br/>
  MockLocalContext is a class which extendes javax.naming.InitialContext class.
  and this is error while creating object of InitialContext.</p>
  
  <p>I am getting the following stack trace:</p>
  
  <pre><code>Exception in thread "main" java.lang.StackOverflowError
  at com.sun.naming.internal.VersionHelper12$2.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at com.sun.naming.internal.VersionHelper12.getJndiProperties(Unknown Source)
  at com.sun.naming.internal.ResourceManager.getInitialEnvironment(Unknown Source)
  at javax.naming.InitialContext.init(Unknown Source)
  at javax.naming.InitialContext.&lt;init&gt;(Unknown Source)
  at net.citigroup.mexico.pg.pgs.mock.MockLocalContext.&lt;init&gt;(MockLocalContext.java:97)
  at net.citigroup.mexico.pg.pgs.mock.MockLocalContext.&lt;init&gt;(MockLocalContext.java:95)
  at net.citigroup.mexico.pg.pgs.mock.MockLocalContext$3$1.getInitialContext(MockLocalContext.java:400)
  at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
  at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
  at javax.naming.InitialContext.init(Unknown Source)
  at javax.naming.InitialContext.&lt;init&gt;(Unknown Source)
  at net.citigroup.mexico.pg.pgs.mock.MockLocalContext.&lt;init&gt;(MockLocalContext.java:97)
  at net.citigroup.mexico.pg.pgs.mock.MockLocalContext.&lt;init&gt;(MockLocalContext.java:95)
  at net.citigroup.mexico.pg.pgs.mock.MockLocalContext$3$1.getInitialContext(MockLocalContext.java:400)
  at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
  at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
  at javax.naming.InitialContext.init(Unknown Source)
  at javax.naming.InitialContext.&lt;init&gt;(Unknown Source)
  at net.citigroup.mexico.pg.pgs.mock.MockLocalContext.&lt;init&gt;(MockLocalContext.java:97)
  at net.citigroup.mexico.pg.pgs.mock.MockLocalContext.&lt;init&gt;(MockLocalContext.java:95)
  at net.citigroup.mexico.pg.pgs.mock.MockLocalContext$3$1.getInitialContext(MockLocalContext.java:400)
  at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
  at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
  at javax.naming.InitialContext.init(Unknown Source)
  at javax.naming.InitialContext.&lt;init&gt;(Unknown Source)
  </code></pre>
  
  <p>It goes one for many lines with the same content, I just trimmed it to fit in here. Thanks! </p>