sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: When `PropertyNotFoundException` are reported as warnings, keep the exception message instead than using the `getValueOrFallback(…)` method. The reason is that the exception message provides a deeper analysis, telling for example if the property can not be provided because it does not exist or because the given name is ambiguous.
Date Tue, 08 Dec 2020 10:07:20 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 2d60d0618ce60b1587079abd92fdfa039903ed98
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Dec 8 10:59:00 2020 +0100

    When `PropertyNotFoundException` are reported as warnings, keep the exception message
instead than using the `getValueOrFallback(…)` method.
    The reason is that the exception message provides a deeper analysis, telling for example
if the property can not be provided because it does
    not exist or because the given name is ambiguous.
---
 .../main/java/org/apache/sis/filter/LeafExpression.java   | 15 ++++++---------
 .../main/java/org/apache/sis/internal/filter/Node.java    | 14 --------------
 2 files changed, 6 insertions(+), 23 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/filter/LeafExpression.java b/core/sis-feature/src/main/java/org/apache/sis/filter/LeafExpression.java
index e17cf24..ef2affd 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/filter/LeafExpression.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/filter/LeafExpression.java
@@ -37,6 +37,7 @@ import org.opengis.feature.PropertyType;
 import org.opengis.feature.AttributeType;
 import org.opengis.feature.IdentifiedType;
 import org.opengis.feature.Operation;
+import org.opengis.feature.PropertyNotFoundException;
 import org.opengis.filter.expression.Expression;
 import org.opengis.filter.expression.ExpressionVisitor;
 
@@ -96,7 +97,6 @@ abstract class LeafExpression extends Node implements Expression, FeatureExpress
     static final class Property extends LeafExpression implements org.opengis.filter.expression.PropertyName
{
         /** For cross-version compatibility. */
         private static final long serialVersionUID = 3417789380239058201L;
-        private static final Object MISSING = new Object();
 
         /** Name of the property from which to retrieve the value. */
         private final String name;
@@ -135,14 +135,11 @@ abstract class LeafExpression extends Node implements Expression, FeatureExpress
          */
         @Override
         public Object evaluate(final Object candidate) {
-            if (candidate instanceof Feature) {
-                Object value = ((Feature) candidate).getValueOrFallback(name, MISSING);
-                if (value == MISSING) {
-                    warning("Property " + name + " undefined on type " + ((Feature) candidate).getType().getName());
-                    // Null will be returned below.
-                } else {
-                    return value;
-                }
+            if (candidate instanceof Feature) try {
+                return ((Feature) candidate).getPropertyValue(name);
+            } catch (PropertyNotFoundException ex) {
+                warning(ex);
+                // Null will be returned below.
             } else if (candidate instanceof Map<?,?>) {
                 return ((Map<?,?>) candidate).get(name);
             }
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/Node.java b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/Node.java
index 651913b..e3057b1 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/Node.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/Node.java
@@ -177,18 +177,4 @@ public abstract class Node implements Serializable {
     protected final void warning(final Exception e) {
         Logging.recoverableException(Logging.getLogger(Loggers.FILTER), getClass(), "evaluate",
e);
     }
-
-    /**
-     * Reports that an operation failed because of an unusual case.
-     * This method assumes that the warning occurred in an {@code evaluate(…)} method.
-     *
-     * @param  message : the description of the error.
-     *
-     * @todo Consider defining a {@code Context} class providing, among other information,
listeners where to report warnings.
-     *
-     * @see <a href="https://issues.apache.org/jira/browse/SIS-460">SIS-460</a>
-     */
-    protected final void warning(final String message) {
-        Logging.recoverableException(Logging.getLogger(Loggers.FILTER), getClass(), message,
null);
-    }
 }


Mime
View raw message