|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -235,6 +235,53 @@ public void operatorInstanceOf() throws Exception {
|
235 | 235 | assertEquals(true,expression.getValue(root));
|
236 | 236 | }
|
237 | 237 |
|
| 238 | + @Test |
| 239 | + public void operatorInstanceOf_SPR14250() throws Exception { |
| 240 | + // primitive left operand - should get boxed, return true |
| 241 | + expression = parse("3 instanceof T(Integer)"); |
| 242 | + assertEquals(true,expression.getValue()); |
| 243 | + assertCanCompile(expression); |
| 244 | + assertEquals(true,expression.getValue()); |
| 245 | + |
| 246 | + // primitive left operand - should get boxed, return false |
| 247 | + expression = parse("3 instanceof T(String)"); |
| 248 | + assertEquals(false,expression.getValue()); |
| 249 | + assertCanCompile(expression); |
| 250 | + assertEquals(false,expression.getValue()); |
| 251 | + |
| 252 | + // double slot left operand - should get boxed, return false |
| 253 | + expression = parse("3.0d instanceof T(Integer)"); |
| 254 | + assertEquals(false,expression.getValue()); |
| 255 | + assertCanCompile(expression); |
| 256 | + assertEquals(false,expression.getValue()); |
| 257 | + |
| 258 | + // double slot left operand - should get boxed, return true |
| 259 | + expression = parse("3.0d instanceof T(Double)"); |
| 260 | + assertEquals(true,expression.getValue()); |
| 261 | + assertCanCompile(expression); |
| 262 | + assertEquals(true,expression.getValue()); |
| 263 | + |
| 264 | + // Only when the right hand operand is a direct type reference |
| 265 | + // will it be compilable. |
| 266 | + StandardEvaluationContext ctx = new StandardEvaluationContext(); |
| 267 | + ctx.setVariable("foo", String.class); |
| 268 | + expression = parse("3 instanceof #foo"); |
| 269 | + assertEquals(false,expression.getValue(ctx)); |
| 270 | + assertCantCompile(expression); |
| 271 | + |
| 272 | + // use of primitive as type for instanceof check - compilable |
| 273 | + // but always false |
| 274 | + expression = parse("3 instanceof T(int)"); |
| 275 | + assertEquals(false,expression.getValue()); |
| 276 | + assertCanCompile(expression); |
| 277 | + assertEquals(false,expression.getValue()); |
| 278 | + |
| 279 | + expression = parse("3 instanceof T(long)"); |
| 280 | + assertEquals(false,expression.getValue()); |
| 281 | + assertCanCompile(expression); |
| 282 | + assertEquals(false,expression.getValue()); |
| 283 | + } |
| 284 | + |
238 | 285 | @Test
|
239 | 286 | public void stringLiteral() throws Exception {
|
240 | 287 | expression = parser.parseExpression("'abcde'");
|
|
0 commit comments