You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2013/10/15 15:32:46 UTC

svn commit: r1532330 - /stanbol/trunk/enhancer/generic/nlp-json/src/main/java/org/apache/stanbol/enhancer/nlp/json/valuetype/ValueTypeParserRegistry.java

Author: rwesten
Date: Tue Oct 15 13:32:46 2013
New Revision: 1532330

URL: http://svn.apache.org/r1532330
Log:
As STANBOL-1132 introduced new ValueTypeParser there is now the possibility the the ServiceLoader encounters NoClassDefFoundError when loading ValueTypeParser services. This e.g. happens if one uses version 0.11.0-SNAPSHOT of the nlp-json module with the 0.10.0 version of the nlp. To avoid that such cases do cause the initialisation to fail the code now catches such exceptions. This allows to write/parse AnalysedText instances that do not use Values of the failing types.

Modified:
    stanbol/trunk/enhancer/generic/nlp-json/src/main/java/org/apache/stanbol/enhancer/nlp/json/valuetype/ValueTypeParserRegistry.java

Modified: stanbol/trunk/enhancer/generic/nlp-json/src/main/java/org/apache/stanbol/enhancer/nlp/json/valuetype/ValueTypeParserRegistry.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancer/generic/nlp-json/src/main/java/org/apache/stanbol/enhancer/nlp/json/valuetype/ValueTypeParserRegistry.java?rev=1532330&r1=1532329&r2=1532330&view=diff
==============================================================================
--- stanbol/trunk/enhancer/generic/nlp-json/src/main/java/org/apache/stanbol/enhancer/nlp/json/valuetype/ValueTypeParserRegistry.java (original)
+++ stanbol/trunk/enhancer/generic/nlp-json/src/main/java/org/apache/stanbol/enhancer/nlp/json/valuetype/ValueTypeParserRegistry.java Tue Oct 15 13:32:46 2013
@@ -134,13 +134,26 @@ public class ValueTypeParserRegistry {
                 valueTypeParsers = new HashMap<Class<?>,ValueTypeParser<?>>();
                 ServiceLoader<ValueTypeParser> loader = ServiceLoader.load(ValueTypeParser.class);
                 for(Iterator<ValueTypeParser> it = loader.iterator();it.hasNext();){
-                    ValueTypeParser vts = it.next();
-                    ValueTypeParser<?> serializer = valueTypeParsers.get(vts.getType());
-                    if(serializer != null){
-                        log.warn("Multiple Parsers for type {} (keep: {}, ignoreing: {}",
-                            new Object[]{vts.getType(),serializer,vts});
-                    } else {
-                        valueTypeParsers.put(vts.getType(), vts);
+                    try {
+                        ValueTypeParser vts = it.next();
+                        ValueTypeParser<?> serializer = valueTypeParsers.get(vts.getType());
+                        if(serializer != null){
+                            log.warn("Multiple Parsers for type {} (keep: {}, ignoreing: {}",
+                                new Object[]{vts.getType(),serializer,vts});
+                        } else {
+                            valueTypeParsers.put(vts.getType(), vts);
+                        }
+                    } catch (NoClassDefFoundError e) {
+                        //ignore services that can not be loaded
+                        //e.g. when mixing different version of the stanbol.enhancer.nlp
+                        //and the stanbol.enhancer.nlp-json module
+                        //It is better to throw an exception if an Node for the failed
+                        //ValueTypeParser appears in the JSON as when loading all
+                        //registered services
+                        log.warn("Unable to load a ValueTypeParser service because class '"
+                            +e.getMessage()+" could not be loaded! This may happen if the "
+                            + "classpath mixes different versions of o.a.stanbol.enhancer.nlp* "
+                            + "modules!");
                     }
                 }
             }