Author: pkluegl
Date: Wed Aug 24 08:41:15 2016
New Revision: 1757473

URL: http://svn.apache.org/viewvc?rev=1757473&view=rev
Log:
no jira - avoid npe for optional match

Modified:
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
    
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1757473&r1=1757472&r2=1757473&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java 
(original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java 
Wed Aug 24 08:41:15 2016
@@ -535,7 +535,7 @@ public class RutaStream extends FSIterat
     return result;
   }
 
-  public List<AnnotationFS> getAnnotationsInWindow2(AnnotationFS 
windowAnnotation, Type type) {
+  private List<AnnotationFS> getAnnotationsInWindow2(AnnotationFS 
windowAnnotation, Type type) {
     List<AnnotationFS> result = new ArrayList<AnnotationFS>();
     windowAnnotation = cas.createAnnotation(type, windowAnnotation.getBegin(),
             windowAnnotation.getEnd() + 1);
@@ -574,8 +574,9 @@ public class RutaStream extends FSIterat
   }
 
   public List<AnnotationFS> getAnnotationsInWindow(AnnotationFS 
windowAnnotation, Type type) {
-    if (type == null)
-      return null;
+    if (windowAnnotation == null || type == null) {
+      return Collections.emptyList();
+    }
     List<AnnotationFS> result = new ArrayList<AnnotationFS>();
     List<AnnotationFS> inWindow = getAnnotationsInWindow2(windowAnnotation, 
type);
     result = inWindow;

Modified: 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
URL: 
http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java?rev=1757473&r1=1757472&r2=1757473&view=diff
==============================================================================
--- 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
 (original)
+++ 
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/SimpleFeatureExpression.java
 Wed Aug 24 08:41:15 2016
@@ -75,11 +75,11 @@ public class SimpleFeatureExpression ext
       IndexedReference indexedReference = 
ParsingUtils.parseIndexedReference(each);
       if (indexedReference.index != -1) {
         Feature delegate = 
type.getFeatureByBaseName(indexedReference.reference);
-        if(delegate != null) {
+        if (delegate != null) {
           feature = new IndexedFeature(delegate, indexedReference.index);
         } else {
-          throw new IllegalArgumentException("Not able to access feature " + 
each + " of type "
-                  + type.getName());
+          throw new IllegalArgumentException(
+                  "Not able to access feature " + each + " of type " + 
type.getName());
         }
       } else if (StringUtils.equals(each, UIMAConstants.FEATURE_COVERED_TEXT)) 
{
         // there is no explicit feature for coveredText
@@ -93,8 +93,8 @@ public class SimpleFeatureExpression ext
           if (StringUtils.equals(each, 
UIMAConstants.FEATURE_COVERED_TEXT_SHORT)) {
             feature = new CoveredTextFeature();
           } else {
-            throw new IllegalArgumentException("Not able to access feature " + 
each + " of type "
-                    + type.getName());
+            throw new IllegalArgumentException(
+                    "Not able to access feature " + each + " of type " + 
type.getName());
           }
         }
       }
@@ -111,13 +111,13 @@ public class SimpleFeatureExpression ext
   @Override
   public Type getInitialType(MatchContext context, RutaStream stream) {
     ITypeExpression typeExpression = mr.getTypeExpression(context, stream);
-    if(typeExpression!= null) {
+    if (typeExpression != null) {
       return typeExpression.getType(context, stream);
     } else {
       IAnnotationExpression annotationExpression = 
mr.getAnnotationExpression(context, stream);
-      if(annotationExpression != null) {
+      if (annotationExpression != null) {
         AnnotationFS annotation = annotationExpression.getAnnotation(context, 
stream);
-        if(annotation != null) {
+        if (annotation != null) {
           return annotation.getType();
         }
       }
@@ -134,9 +134,10 @@ public class SimpleFeatureExpression ext
 
     Collection<AnnotationFS> result = new TreeSet<AnnotationFS>(comparator);
     List<Feature> features = getFeatures(context, stream);
-    if(features!= null &&!features.isEmpty()) {
-      collectFeatureAnnotations(annotations, features, checkOnFeatureValue, 
result, stream, context);
-    return result;
+    if (features != null && !features.isEmpty()) {
+      collectFeatureAnnotations(annotations, features, checkOnFeatureValue, 
result, stream,
+              context);
+      return result;
     } else {
       return annotations;
     }
@@ -213,19 +214,19 @@ public class SimpleFeatureExpression ext
     }
 
     int index = -1;
-    if(currentFeature instanceof IndexedFeature) {
+    if (currentFeature instanceof IndexedFeature) {
       IndexedFeature indexedFeature = (IndexedFeature) currentFeature;
       currentFeature = indexedFeature.getDelegate();
       index = indexedFeature.getIndex();
     }
-    
+
     FeatureStructure value = annotation.getFeatureValue(currentFeature);
     if (value instanceof AnnotationFS) {
       AnnotationFS next = (AnnotationFS) value;
       collectFeatureAnnotations(next, tail, checkOnFeatureValue, result, 
stream, context);
     } else if (value instanceof FSArray && index >= 0) {
       FSArray array = (FSArray) value;
-      if(index < array.size()) {
+      if (index < array.size()) {
         FeatureStructure fs = array.get(index);
         if (fs instanceof AnnotationFS) {
           AnnotationFS next = (AnnotationFS) fs;
@@ -245,8 +246,8 @@ public class SimpleFeatureExpression ext
     } else if (value != null) {
       result.add(annotation);
       // primitive? -> return last annotation for further processing
-//      throw new IllegalArgumentException(value.getType()
-//              + " is not supported in a feature match expression (" + 
mr.getMatch() + ").");
+      // throw new IllegalArgumentException(value.getType()
+      // + " is not supported in a feature match expression (" + mr.getMatch() 
+ ").");
     }
   }
 


Reply via email to