title: Parsing Local XML File with DocumentBuilder Throws SocketException (Connection Reset) Sometimes in Java
body: <p>I've seen some similar posts on here and tried to amend their approach to this problem, but nothing has directly addressed my exact issue nor worked so far.</p>
  
  <p>So I have some code that needs to read in an xml file. I implemented it in java using the java.xml.parsers classes (mainly document builder).</p>
  
  <p>The relevant code is below:</p>
  
  <pre><code>public NodeList setupXmlFile(File xmlFile) {
      xmlToParse = xmlFile;
      DocumentBuilder builder;
      Document toRead;
      try {
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          dbf.setValidating(false);
          builder = dbf.newDocumentBuilder();
          toRead = builder.parse(xmlToParse);
      } catch (ParserConfigurationException | SAXException | IOException e) {
          if (Main.LOGGING) {
              System.out.println("ERROR: Couldn't open the xml file to read. Possibly an incorrect name.");
              e.printStackTrace();
          }
          return null;
      }       
  
      return toRead.getChildNodes();
  }
  </code></pre>
  
  <p>I am passing in a real file that was previously constructed from the local path (on the server or my local machine). That file is always there and has never been uploaded or modified or anything strange. xmlToParse is a global so that's why there's no definition here.</p>
  
  <p>The strange thing is, I had this completely working and live on a website for about a month with it producing results. Now seemingly without anything changing, both the website version and my local version won't read in files. I can't seem to pin down the cause.</p>
  
  <p>Here is the exact exception I'm getting:</p>
  
  <pre><code>java.net.SocketException: Connection reset
  at java.net.SocketInputStream.read(SocketInputStream.java:189)
  at java.net.SocketInputStream.read(SocketInputStream.java:121)
  at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
  at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
  at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
  at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:703)
  at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
  at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:674)
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1535)
  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
  at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:646)
  at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1300)
  at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1267)
  at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:263)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1164)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1050)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:964)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
  at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
  at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
  at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
  at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
  at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348)
  at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:205)
  at Visitors.NoteComplexityVisitor.setupXmlFile(NoteComplexityVisitor.java:169)
  at Visitors.NoteComplexityVisitor.&lt;init&gt;(NoteComplexityVisitor.java:104)
  at Main.Scorer.&lt;init&gt;(Scorer.java:39)
  at Main.Main.main(Main.java:61)
  </code></pre>
  
  <p>I'd like to stay as far away from sockets as possible since I'm only dealing with local files and never streaming/uploading anything. I've verified that the file is indeed there by copying the exact path over to the terminal and going to it. When I malformed that file path, I get a different exception for the file being incorrect, so I seem to have eliminated that possibility. Again, I can't seem to grasp why both versions suddenly stopped working. I can verify that nothing has changed on my github repo as well, so I'm not missing anything simple I don't think (at least I hope). Please help and thank you so much!</p>