From 37b0dc2dffae3f513f1039f308366d68bd10d238 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 14 Jun 2017 09:58:22 +0200 Subject: [PATCH] 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. --- .../data/rest/webmvc/json/patch/PatchOperation.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java index cd8dbe5b7..aa35ea499 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java @@ -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 {