From bee8477d42d487287a96d4d15e42b6845deecaec Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Tue, 25 May 2021 11:45:27 +0100 Subject: [PATCH] Update the implementation for generics changes --- .../com/sun/el/ExpressionFactoryImpl.java | 5 +++-- .../main/java/com/sun/el/lang/ELSupport.java | 21 ++++++++++--------- .../com/sun/el/lang/EvaluationContext.java | 5 +++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/impl/src/main/java/com/sun/el/ExpressionFactoryImpl.java b/impl/src/main/java/com/sun/el/ExpressionFactoryImpl.java index 71efa55c..c0a32a90 100644 --- a/impl/src/main/java/com/sun/el/ExpressionFactoryImpl.java +++ b/impl/src/main/java/com/sun/el/ExpressionFactoryImpl.java @@ -1,5 +1,6 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates and others. + * All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -63,7 +64,7 @@ public ExpressionFactoryImpl(Properties properties) { * "jakarta.el.bc2.2" set to true. */ @Override - public Object coerceToType(Object obj, Class type) { + public T coerceToType(Object obj, Class type) { try { return ELSupport.coerceToType(obj, type, isBackwardCompatible22); } catch (IllegalArgumentException ex) { diff --git a/impl/src/main/java/com/sun/el/lang/ELSupport.java b/impl/src/main/java/com/sun/el/lang/ELSupport.java index 1ecb9272..494a3340 100644 --- a/impl/src/main/java/com/sun/el/lang/ELSupport.java +++ b/impl/src/main/java/com/sun/el/lang/ELSupport.java @@ -1,5 +1,6 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates and others. + * All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -334,14 +335,14 @@ public final static void checkType(final Object obj, final Class type) throws } } - public final static Object coerceToType(final Object obj, final Class type) throws IllegalArgumentException { + public final static T coerceToType(final Object obj, final Class type) throws IllegalArgumentException { return coerceToType(obj, type, false); } - public final static Object coerceToType(final Object obj, final Class type, boolean isEL22Compatible) throws IllegalArgumentException { + public final static T coerceToType(final Object obj, final Class type, boolean isEL22Compatible) throws IllegalArgumentException { if (type == null || Object.class.equals(type) || (obj != null && type.isAssignableFrom(obj.getClass()))) { - return obj; + return (T) obj; } // New in 3.0 @@ -350,19 +351,19 @@ public final static Object coerceToType(final Object obj, final Class type, b } if (String.class.equals(type)) { - return coerceToString(obj); + return (T) coerceToString(obj); } if (ELArithmetic.isNumberType(type)) { - return coerceToNumber(obj, type); + return (T) coerceToNumber(obj, type); } if (Character.class.equals(type) || Character.TYPE == type) { - return coerceToCharacter(obj); + return (T) coerceToCharacter(obj); } if (Boolean.class.equals(type) || Boolean.TYPE == type) { - return coerceToBoolean(obj); + return (T) coerceToBoolean(obj); } if (type.isEnum()) { - return coerceToEnum(obj, type); + return (T) coerceToEnum(obj, type); } if (obj == null) { @@ -376,7 +377,7 @@ public final static Object coerceToType(final Object obj, final Class type, b PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor != null) { editor.setAsText((String) obj); - return editor.getValue(); + return (T) editor.getValue(); } } throw new IllegalArgumentException(MessageFactory.get("error.convert", obj, obj.getClass(), type)); diff --git a/impl/src/main/java/com/sun/el/lang/EvaluationContext.java b/impl/src/main/java/com/sun/el/lang/EvaluationContext.java index e46dad2c..a5f074e6 100644 --- a/impl/src/main/java/com/sun/el/lang/EvaluationContext.java +++ b/impl/src/main/java/com/sun/el/lang/EvaluationContext.java @@ -1,5 +1,6 @@ /* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2021 Oracle and/or its affiliates and others. + * All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -133,7 +134,7 @@ public void exitLambdaScope() { } @Override - public Object convertToType(Object obj, Class targetType) { + public T convertToType(Object obj, Class targetType) { return elContext.convertToType(obj, targetType); }