From 241a50a40902f81ecdafaa8cfd6c988a418ddfb9 Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Wed, 8 Sep 2010 12:48:25 +0000 Subject: [PATCH] Merged BRANCHES/DEV/V3.3-BUG-FIX to HEAD: 22328: Merged BRANCHES/V3.3 to BRANCHES/DEV/V3.3-BUG-FIX: 22327: Merged BRANCHES/DEV/BELARUS/V3.3-BUG-FIX-2010_08_11 to BRANCHES/V3.3 (+ additional fix) 22132: ALF-4461: Dictionary code leaks file handles (also fixed other non-test usage - DictionaryModelType) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22330 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/dictionary/DictionaryModelType.java | 24 ++++++++++++++++++- .../DictionaryRepositoryBootstrap.java | 23 +++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java b/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java index 983c208145..449559371c 100644 --- a/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java +++ b/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java @@ -18,6 +18,8 @@ */ package org.alfresco.repo.dictionary; +import java.io.IOException; +import java.io.InputStream; import java.io.Serializable; import java.util.Collection; import java.util.HashSet; @@ -637,7 +639,27 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda if (contentReader != null) { // Create a model from the current content - M2Model m2Model = M2Model.createModel(contentReader.getContentInputStream()); + M2Model m2Model = null; + InputStream is = null; + try + { + is = contentReader.getContentInputStream(); + m2Model = M2Model.createModel(is); + } + finally + { + if (is != null) + { + try + { + is.close(); + } + catch (IOException e) + { + logger.error("Failed to close input stream for " + nodeRef); + } + } + } // Try and compile the model CompiledModel compiledModel= m2Model.compile(dictionaryDAO, namespaceDAO); diff --git a/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java b/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java index b88e9893e3..ed6e1fdfdc 100644 --- a/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java +++ b/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java @@ -18,6 +18,8 @@ */ package org.alfresco.repo.dictionary; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -474,7 +476,26 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme } else { - model = M2Model.createModel(contentReader.getContentInputStream()); + InputStream is = null; + try + { + is = contentReader.getContentInputStream(); + model = M2Model.createModel(is); + } + finally + { + if (is != null) + { + try + { + is.close(); + } + catch (IOException e) + { + logger.error("Failed to close input stream for " + nodeRef); + } + } + } } } // TODO should we inactivate the model node and put the error somewhere??