Author: rombert Date: Fri Oct 24 23:11:54 2014 New Revision: 1634154 URL: http://svn.apache.org/r1634154 Log: SLING-4092: Eclipse runs out of file descriptors due to vault files being kept open
Ensure that InputStream instances returned from IFile.getContents() are closed. Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java?rev=1634154&r1=1634153&r2=1634154&view=diff ============================================================================== --- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java (original) +++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/GenericJcrRootFile.java Fri Oct 24 23:11:54 2014 @@ -24,6 +24,7 @@ import java.util.List; import javax.xml.parsers.ParserConfigurationException; +import org.apache.commons.io.IOUtils; import org.apache.sling.ide.eclipse.core.internal.Activator; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; @@ -54,8 +55,12 @@ public class GenericJcrRootFile extends this.domElement = null; InputStream in = file.getContents(); - this.document = TolerantXMLParser.parse(in, file.getFullPath().toOSString()); - handleJcrRoot(this.document.getRootElement()); + try { + this.document = TolerantXMLParser.parse(in, file.getFullPath().toOSString()); + handleJcrRoot(this.document.getRootElement()); + } finally { + IOUtils.closeQuietly(in); + } } @Override Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java?rev=1634154&r1=1634153&r2=1634154&view=diff ============================================================================== --- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java (original) +++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java Fri Oct 24 23:11:54 2014 @@ -37,6 +37,7 @@ import javax.xml.parsers.ParserConfigura import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.apache.commons.io.IOUtils; import org.apache.jackrabbit.util.ISO9075; import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer; import org.apache.sling.ide.eclipse.core.ProjectUtil; @@ -441,9 +442,13 @@ public class JcrNode implements IAdaptab SAXParser saxParser = factory.newSAXParser(); JcrRootHandler h = new JcrRootHandler(); - saxParser.parse(new InputSource(file.getContents()), h); - - return h.isVaultFile(); + InputStream contents = file.getContents(); + try { + saxParser.parse(new InputSource(contents), h); + return h.isVaultFile(); + } finally { + IOUtils.closeQuietly(contents); + } } return false; } @@ -1436,8 +1441,9 @@ public class JcrNode implements IAdaptab IFolder contentSyncRoot = ProjectUtil.getSyncDirectory(getProject()); IFile file = (IFile) u.file; + InputStream contents = null; try{ - InputStream contents = file.getContents(); + contents = file.getContents(); String resourceLocation = file.getFullPath().makeRelativeTo(contentSyncRoot.getFullPath()) .toPortableString(); ResourceProxy resourceProxy = Activator.getDefault() @@ -1449,6 +1455,8 @@ public class JcrNode implements IAdaptab return PropertyTypeSupport.propertyTypeOfString(rawValue); } catch(Exception e) { Activator.getDefault().getPluginLogger().warn("Exception occurred during analyzing propertyType ("+propertyName+") for "+this, e); + } finally { + IOUtils.closeQuietly(contents); } return -1; }