title: variable "context" might not have been initialized, java JNDI util
body: <p>I am currently working on a project for a company, and we have taken an open-source family tree project from Microsoft (The source function can be found here: <a href="https://familyhistory.hhs.gov/fhh-web/home.action" rel="nofollow">Family History</a> and the source code on their <a href="http://gforge.nci.nih.gov/projects/fhh" rel="nofollow">GForge</a>), but I've run into issues the whole time. I've solve most compilation errors for the most part, because they were simple exception errors, but this one is one I haven't been able to solve yet. I've Googled the problem and found many similar solutions, but none seem to work quite right. If you need any more information please let me know, I'll do my best to try and provide it to you. Although, I am still a beginner in java. </p>
  
  <p>The compiler (which is a Apache Maven 2.2.1) gives me the following error:</p>
  
  <pre><code>C:\mfhp-2.4.0\services\src\main\java\gov\hhs\fhh\service\locator\JndiUtil.java:
  [68,4] variable context might not have been initialized
  </code></pre>
  
  <p>Here is the code for the file:</p>
  
  <pre><code>public final class JndiUtil {
  
  private static final Logger LOG = Logger.getLogger(JndiUtil.class);
  private static final String RESOURCE_NAME = "jndi.properties";
  
  private static JndiUtil theInstance = new JndiUtil();
  
  private final InitialContext context;
  
  private JndiUtil() {
      try {
          Properties props = getProperties();
          context = new InitialContext(props);
      } catch (NamingException e) { //This was a fix I did
          LOG.error("Unable to initialize the JNDI Util.", e);
          throw new IllegalStateException(e);
      } catch (IOException ioe) { //This was a fix I did
      LOG.error("IOException", ioe);
      }
  }
  
  /**
   * @return jndi (&amp; jms) properties
   * @throws IOException on class load error
   */
  public static Properties getProperties() throws IOException {
      Properties props = new Properties();
      props.load(JndiUtil.class.getClassLoader().getResourceAsStream(RESOURCE_NAME));
      return props;
  }
  
  /**
   * @param name name to lookup
   * @return object in default context with given name
   */
  public static Object lookup(String name) {
      return lookup(theInstance.context, name);
  }
  
  /**
   * @param ctx context
   * @param name name to get
   * @return object in contect with given name
   */
  public static Object lookup(InitialContext ctx, String name) {
      try {
          return ctx.lookup(name);
      } catch (NamingException ex) {
          //LOG.error("------------------Here is what's in the context--(looking for " + name + ")----------");
          LOG.error("------------------Error looking up ctx context for: " + name + ")----------");
          //dump(ctx, 0);
          //LOG.error("-----------------------------------------------------------");
          throw new IllegalStateException(ex);
      }
  }
  /*
   * Method taken out to avoid looping messages into log file
  private static void dump(javax.naming.Context ctx, int indent) {
      try {
          NamingEnumeration&lt;NameClassPair&gt; en = ctx.list("");
          while (en.hasMore()) {
              NameClassPair ncp = en.next();
              String cn = ncp.getClassName();
              String n = ncp.getName();
              LOG.info("\t\t\t\t\t\t".substring(0, indent) + n + " : " + cn);
              try {
                  Object o = ctx.lookup(n);
                  if (o instanceof Context) {
                      dump((Context) o, indent + 1);
                  }
              } catch (Exception e) {
                  LOG.info(e);
              }
          }
      } catch (NamingException ex) {
          LOG.info(ex);
      }
  }
  */
  }
  </code></pre>