Author: rwesten
Date: Tue Oct 22 09:30:26 2013
New Revision: 1534559

URL: http://svn.apache.org/r1534559
Log:
STANBOL-864: Somehow the fix for this issue is missing in the trunk. Need to 
releasing-0.12 as well! The issue itself is marked as fixed in commons-0.11.0 
...

Modified:
    
stanbol/trunk/commons/opennlp/src/main/java/org/apache/stanbol/commons/opennlp/OpenNLP.java
    
stanbol/trunk/commons/opennlp/src/test/java/org/apache/commons/opennlp/OpenNLPTest.java

Modified: 
stanbol/trunk/commons/opennlp/src/main/java/org/apache/stanbol/commons/opennlp/OpenNLP.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/opennlp/src/main/java/org/apache/stanbol/commons/opennlp/OpenNLP.java?rev=1534559&r1=1534558&r2=1534559&view=diff
==============================================================================
--- 
stanbol/trunk/commons/opennlp/src/main/java/org/apache/stanbol/commons/opennlp/OpenNLP.java
 (original)
+++ 
stanbol/trunk/commons/opennlp/src/main/java/org/apache/stanbol/commons/opennlp/OpenNLP.java
 Tue Oct 22 09:30:26 2013
@@ -21,6 +21,9 @@ import java.io.InputStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.nio.charset.Charset;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -537,8 +540,21 @@ public class OpenNLP {
      * @return the stream or <code>null</code> if not found
      * @throws IOException an any error while opening the model file
      */
-    protected InputStream lookupModelStream(String modelName, 
Map<String,String> properties) throws IOException {
-        return dataFileProvider.getInputStream(null, modelName,properties);
+    protected InputStream lookupModelStream(final String modelName, final 
Map<String,String> properties) throws IOException {
+        try {
+            return AccessController.doPrivileged(new 
PrivilegedExceptionAction<InputStream>() {
+                public InputStream run() throws IOException {
+                    return dataFileProvider.getInputStream(null, 
modelName,properties);
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            Exception e = pae.getException();
+            if(e instanceof IOException){
+                throw (IOException)e;
+            } else {
+                throw RuntimeException.class.cast(e);
+            }
+        }        
     }
 
     /**

Modified: 
stanbol/trunk/commons/opennlp/src/test/java/org/apache/commons/opennlp/OpenNLPTest.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/commons/opennlp/src/test/java/org/apache/commons/opennlp/OpenNLPTest.java?rev=1534559&r1=1534558&r2=1534559&view=diff
==============================================================================
--- 
stanbol/trunk/commons/opennlp/src/test/java/org/apache/commons/opennlp/OpenNLPTest.java
 (original)
+++ 
stanbol/trunk/commons/opennlp/src/test/java/org/apache/commons/opennlp/OpenNLPTest.java
 Tue Oct 22 09:30:26 2013
@@ -1,3 +1,19 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 package org.apache.commons.opennlp;
 
 import java.io.IOException;
@@ -140,6 +156,7 @@ public class OpenNLPTest {
         tokenModel = openNLP.getModel(TokenizerModel.class, "ru-token.bin", 
null);
         Assert.assertNull(tokenModel);
     }
+    
     @Test(expected=IllegalStateException.class)
     public void testLoadIncompatibleModelByName() throws IOException{
         SentenceModel sentModel = openNLP.getModel(SentenceModel.class, 
"en-token.bin", null);


Reply via email to