MCPcopy Create free account
hub / github.com/apache/tomcat / coerceToBoolean

Method coerceToBoolean

java/org/apache/el/lang/ELSupport.java:243–274  ·  view source on GitHub ↗

Convert an object to Boolean. Null and empty string are false. @param ctx the context in which this conversion is taking place @param obj the object to convert @param primitive is the target a primitive in which case coercion to null is not permitted @return the Boolean value of the ob

(final ELContext ctx, final Object obj, boolean primitive)

Source from the content-addressed store, hash-verified

241 * @throws ELException if object is not Boolean or String
242 */
243 public static Boolean coerceToBoolean(final ELContext ctx, final Object obj, boolean primitive) throws ELException {
244
245 if (ctx != null) {
246 boolean originalIsPropertyResolved = ctx.isPropertyResolved();
247 try {
248 Boolean result = ctx.getELResolver().convertToType(ctx, obj, Boolean.class);
249 if (ctx.isPropertyResolved()) {
250 return result;
251 }
252 } finally {
253 ctx.setPropertyResolved(originalIsPropertyResolved);
254 }
255 }
256
257 if (!COERCE_TO_ZERO && !primitive) {
258 if (obj == null) {
259 return null;
260 }
261 }
262
263 if (obj == null || "".equals(obj)) {
264 return Boolean.FALSE;
265 }
266 if (obj instanceof Boolean) {
267 return (Boolean) obj;
268 }
269 if (obj instanceof String) {
270 return Boolean.valueOf((String) obj);
271 }
272
273 throw new ELException(MessageFactory.get("error.convert", obj, obj.getClass(), Boolean.class));
274 }
275
276 private static Character coerceToCharacter(final ELContext ctx, final Object obj) throws ELException {
277

Callers 9

testCoerceToBoolean01Method · 0.95
testCoerceToBoolean02Method · 0.95
equalsMethod · 0.95
coerceToTypeMethod · 0.95
getValueMethod · 0.95
getValueMethod · 0.95
getValueMethod · 0.95
getValueMethod · 0.95
findNextMethod · 0.95

Calls 7

getMethod · 0.95
equalsMethod · 0.65
isPropertyResolvedMethod · 0.45
convertToTypeMethod · 0.45
getELResolverMethod · 0.45
setPropertyResolvedMethod · 0.45
valueOfMethod · 0.45

Tested by 2

testCoerceToBoolean01Method · 0.76
testCoerceToBoolean02Method · 0.76