int suffixIndex = skipToCorrectEndSuffix(suffix, expressionString, afterPrefixIndex); if (suffixIndex == -1) { throw new ParseException(expressionString, prefixIndex, "No ending suffix '" + suffix + "' for expression starting at character " + prefixIndex + ": " + expressionString.substring(prefixIndex)); throw new ParseException(expressionString, prefixIndex, "No expression defined within delimiter '" + prefix + suffix + "' at character " + prefixIndex); expr = expr.trim(); if (expr.isEmpty()) { throw new ParseException(expressionString, prefixIndex, "No expression defined within delimiter '" + prefix + suffix + "' at character " + prefixIndex);
public PreInvocationAttribute createPreInvocationAttribute(String preFilterAttribute, String filterObject, String preAuthorizeAttribute) { try { // TODO: Optimization of permitAll ExpressionParser parser = getParser(); Expression preAuthorizeExpression = preAuthorizeAttribute == null ? parser .parseExpression("permitAll") : parser .parseExpression(preAuthorizeAttribute); Expression preFilterExpression = preFilterAttribute == null ? null : parser .parseExpression(preFilterAttribute); return new PreInvocationExpressionAttribute(preFilterExpression, filterObject, preAuthorizeExpression); } catch (ParseException e) { throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e); } }
/** * Call setValue() but expect it to fail. */ protected void setValueExpectError(String expression, Object value) { try { Expression e = parser.parseExpression(expression); if (e == null) { fail("Parser returned null for expression"); } if (DEBUG) { SpelUtilities.printAbstractSyntaxTree(System.out, e); } StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext(); e.setValue(lContext, value); fail("expected an error"); } catch (ParseException pe) { pe.printStackTrace(); fail("Unexpected Exception: " + pe.getMessage()); } catch (EvaluationException ee) { // success! } }
@Test public void testErrorCases() throws Exception { try { parser.parseExpression("hello ${'world'", DEFAULT_TEMPLATE_PARSER_CONTEXT); fail("Should have failed"); } catch (ParseException pe) { assertEquals("No ending suffix '}' for expression starting at character 6: ${'world'", pe.getSimpleMessage()); assertEquals("hello ${'world'", pe.getExpressionString()); } try { parser.parseExpression("hello ${'wibble'${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT); fail("Should have failed"); } catch (ParseException pe) { assertEquals("No ending suffix '}' for expression starting at character 6: ${'wibble'${'world'}", pe.getSimpleMessage()); } try { parser.parseExpression("hello ${} world", DEFAULT_TEMPLATE_PARSER_CONTEXT); fail("Should have failed"); } catch (ParseException pe) { assertEquals("No expression defined within delimiter '${}' at character 6", pe.getSimpleMessage()); } }
assertEquals(SpelMessage.MISSING_CONSTRUCTOR_ARGS, spe.getMessageCode()); assertEquals(10, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString())); assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode()); assertEquals(10, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString())); assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode()); assertEquals(10, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString())); assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode()); assertEquals(10, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString())); assertEquals(SpelMessage.NON_TERMINATING_DOUBLE_QUOTED_STRING, spe.getMessageCode()); assertEquals(0, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString())); assertEquals(SpelMessage.NON_TERMINATING_QUOTED_STRING, spe.getMessageCode()); assertEquals(0, spe.getPosition()); assertTrue(ex.getMessage().contains(ex.getExpressionString()));
/** * check filter and generate more friendly message than CT normally does * * @param partitionFilter */ private void checkSpelFilter(String partitionFilter) { LOG.info("Located partition filter expression: {}", partitionFilter); try { expressionParser.parse(partitionFilter); } catch (ParseException e) { System.out.println("WARNING: There was a problem parsing your expression. Check above to see what was " + "resolved from the YML file to see if it is what you expect."); System.out.println("Perhaps you are inadvertently creating a YAML comment with '#{ #'?"); e.printStackTrace(System.out); return; } } }
assertEquals("No ending suffix '}' for expression starting at character 41: ${listOfNumbersUpToTen.$[#this>5] world", pe.getSimpleMessage()); assertEquals("Found closing '}' at position 74 but most recent opening is '[' at position 30", pe.getSimpleMessage());
/** * check filter and generate more friendly message than CT normally does * * @param partitionFilter */ private void checkSpelFilter(String partitionFilter) { LOG.info("Located partition filter expression: {}", partitionFilter); try { expressionParser.parse(partitionFilter); } catch (ParseException e) { System.out.println("WARNING: There was a problem parsing your expression. Check above to see what was " + "resolved from the YML file to see if it is what you expect."); System.out.println("Perhaps you are inadvertently creating a YAML comment with '#{ #'?"); e.printStackTrace(System.out); return; } } }
case ')': if (stack.isEmpty()) { throw new ParseException(expressionString, pos, "Found closing '" + ch + "' at position " + pos + " without an opening '" + Bracket.theOpenBracketFor(ch) + "'"); throw new ParseException(expressionString, pos, "Found closing '" + ch + "' at position " + pos + " but most recent opening is '" + p.bracket + "' at position " + p.pos); throw new ParseException(expressionString, pos, "Found non terminating string literal starting at position " + pos); throw new ParseException(expressionString, p.pos, "Missing closing '" + Bracket.theCloseBracketFor(p.bracket) + "' for '" + p.bracket + "' at position " + p.pos);
public PostInvocationAttribute createPostInvocationAttribute( String postFilterAttribute, String postAuthorizeAttribute) { try { ExpressionParser parser = getParser(); Expression postAuthorizeExpression = postAuthorizeAttribute == null ? null : parser.parseExpression(postAuthorizeAttribute); Expression postFilterExpression = postFilterAttribute == null ? null : parser .parseExpression(postFilterAttribute); if (postFilterExpression != null || postAuthorizeExpression != null) { return new PostInvocationExpressionAttribute(postFilterExpression, postAuthorizeExpression); } } catch (ParseException e) { throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e); } return null; }
/** * Parse the supplied expression and then create a string representation of the resultant AST, it should be the * expected value. * * @param expression the expression to parse * @param expectedStringFormOfAST the expected string form of the AST */ public void parseCheck(String expression, String expectedStringFormOfAST) { try { SpelExpression e = parser.parseRaw(expression); if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) { SpelUtilities.printAbstractSyntaxTree(System.err, e); } if (e == null) { fail("Parsed exception was null"); } assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST()); } catch (ParseException ee) { ee.printStackTrace(); fail("Unexpected Exception: " + ee.getMessage()); } }
int suffixIndex = skipToCorrectEndSuffix(suffix, expressionString, afterPrefixIndex); if (suffixIndex == -1) { throw new ParseException(expressionString, prefixIndex, "No ending suffix '" + suffix + "' for expression starting at character " + prefixIndex + ": " + expressionString.substring(prefixIndex)); throw new ParseException(expressionString, prefixIndex, "No expression defined within delimiter '" + prefix + suffix + "' at character " + prefixIndex); expr = expr.trim(); if (expr.isEmpty()) { throw new ParseException(expressionString, prefixIndex, "No expression defined within delimiter '" + prefix + suffix + "' at character " + prefixIndex);
public PreInvocationAttribute createPreInvocationAttribute(String preFilterAttribute, String filterObject, String preAuthorizeAttribute) { try { // TODO: Optimization of permitAll ExpressionParser parser = getParser(); Expression preAuthorizeExpression = preAuthorizeAttribute == null ? parser .parseExpression("permitAll") : parser .parseExpression(preAuthorizeAttribute); Expression preFilterExpression = preFilterAttribute == null ? null : parser .parseExpression(preFilterAttribute); return new PreInvocationExpressionAttribute(preFilterExpression, filterObject, preAuthorizeExpression); } catch (ParseException e) { throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e); } }
case ')': if (stack.isEmpty()) { throw new ParseException(expressionString, pos, "Found closing '" + ch + "' at position " + pos + " without an opening '" + Bracket.theOpenBracketFor(ch) + "'"); throw new ParseException(expressionString, pos, "Found closing '" + ch + "' at position " + pos + " but most recent opening is '" + p.bracket + "' at position " + p.pos); throw new ParseException(expressionString, pos, "Found non terminating string literal starting at position " + pos); throw new ParseException(expressionString, p.pos, "Missing closing '" + Bracket.theCloseBracketFor(p.bracket) + "' for '" + p.bracket + "' at position " + p.pos);
public PostInvocationAttribute createPostInvocationAttribute( String postFilterAttribute, String postAuthorizeAttribute) { try { ExpressionParser parser = getParser(); Expression postAuthorizeExpression = postAuthorizeAttribute == null ? null : parser.parseExpression(postAuthorizeAttribute); Expression postFilterExpression = postFilterAttribute == null ? null : parser .parseExpression(postFilterAttribute); if (postFilterExpression != null || postAuthorizeExpression != null) { return new PostInvocationExpressionAttribute(postFilterExpression, postAuthorizeExpression); } } catch (ParseException e) { throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e); } return null; }
private void error(String message) { throw new ParseException(0, message + ".\n" + "Must be one of: " + ATTRIBUTES); } }
public PreInvocationAttribute createPreInvocationAttribute(String preFilterAttribute, String filterObject, String preAuthorizeAttribute) { try { // TODO: Optimization of permitAll Expression preAuthorizeExpression = preAuthorizeAttribute == null ? parser.parseExpression("permitAll") : parser.parseExpression(preAuthorizeAttribute); Expression preFilterExpression = preFilterAttribute == null ? null : parser.parseExpression(preFilterAttribute); return new PreInvocationExpressionAttribute(preFilterExpression, filterObject, preAuthorizeExpression); } catch (ParseException e) { throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e); } }
private void error(String message) { throw new ParseException(0, message + ".\n" + "Must be one of: " + ATTRIBUTES); } }
public PostInvocationAttribute createPostInvocationAttribute(String postFilterAttribute, String postAuthorizeAttribute) { try { Expression postAuthorizeExpression = postAuthorizeAttribute == null ? null : parser.parseExpression(postAuthorizeAttribute); Expression postFilterExpression = postFilterAttribute == null ? null : parser.parseExpression(postFilterAttribute); if (postFilterExpression != null || postAuthorizeExpression != null) { return new PostInvocationExpressionAttribute(postFilterExpression, postAuthorizeExpression); } } catch (ParseException e) { throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e); } return null; } }
int suffixIndex = skipToCorrectEndSuffix(suffix, expressionString, afterPrefixIndex); if (suffixIndex == -1) { throw new ParseException(expressionString, prefixIndex, "No ending suffix '" + suffix + "' for expression starting at character " + prefixIndex + ": " + expressionString.substring(prefixIndex)); throw new ParseException(expressionString, prefixIndex, "No expression defined within delimiter '" + prefix + suffix + "' at character " + prefixIndex); expr = expr.trim(); if (expr.isEmpty()) { throw new ParseException(expressionString, prefixIndex, "No expression defined within delimiter '" + prefix + suffix + "' at character " + prefixIndex);