DATAREST-1092 - Improve exception handling in PatchOperation for Spring 5 compatibility.

We now also catch SpelEvaluationException in the attempt to set a null value for an expression as Spring 5 now reports a failed attempt (e.g. if the target type is not nullable) using that type whereas Spring 4.3 threw a NullPointerException.
This commit is contained in:
Oliver Gierke
2017-06-14 09:58:22 +02:00
parent bc5a265ff9
commit 37b0dc2dff

View File

@@ -24,6 +24,7 @@ import org.springframework.core.CollectionFactory;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionException;
import org.springframework.expression.spel.SpelEvaluationException;
/**
* Abstract base class representing and providing support methods for patch operations.
@@ -104,8 +105,10 @@ public abstract class PatchOperation {
try {
expression.setValue(target, null);
return value;
} catch (NullPointerException e) {
throw new PatchException("Path '" + removePath + "' is not nullable.");
} catch (NullPointerException o_O) {
throw new PatchException("Path '" + removePath + "' is not nullable.", o_O);
} catch (SpelEvaluationException o_O) {
throw new PatchException("Path '" + removePath + "' is not nullable.", o_O);
}
} else {