We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AviatorString类的compare方法未考虑this.lexeme为null以及otherString.lexeme为null的情况。这导致以下两种不符合预期的case
return this.lexeme.compareTo(otherString.lexeme);
return this.lexeme.compareTo(String.valueOf(otherJavaValue));
该代码在this.lexeme为null,或者otherString.lexeme为null时,均会抛出空指针异常。
下面是我用到的测试case
public class StringGetFromJsonMapFunction extends AbstractFunction { @Override public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) { //blablala //始终返回null return new AviatorString(null); } @Override public String getName() { return "string.getFromJsonMap"; } }
进行如下测试
@Test public void testNullPointerException() { String exp = "string.getFromJsonMap(mapJson, key) == 'abc'"; Map<String, Object> env = Maps.newHashMap(); env.put("mapJson", "{\"key1\":\"value1\", \"key2\":\"value2\"}"); env.put("key", "key3"); //预期返回false,实际上却抛出了空指针异常。 assertEquals(false, (Boolean)AviatorEvaluator.execute(exp, env)); } @Test public void testNil() { String exp = "string.getFromJsonMap(mapJson, key) == nil"; Map<String, Object> env = Maps.newHashMap(); env.put("mapJson", "{\"key1\":\"value1\", \"key2\":\"value2\"}"); env.put("key", "key3"); //预期返回true,实际上却返回false。 assertEquals(true, (Boolean)AviatorEvaluator.execute(exp, env)); }
附AviatorString的compare方法源码 (Aviator 3.0.0版本)
public int compare(AviatorObject other, Map<String, Object> env) { if (this == other) { return 0; } switch (other.getAviatorType()) { case String: AviatorString otherString = (AviatorString) other; return this.lexeme.compareTo(otherString.lexeme); //可能抛出空指针 case JavaType: AviatorJavaType javaType = (AviatorJavaType) other; final Object otherJavaValue = javaType.getValue(env); if (otherJavaValue == null) { return 1; } if(TypeUtils.isString(otherJavaValue)) { return this.lexeme.compareTo(String.valueOf(otherJavaValue)); //可能抛出空指针 } else if (otherJavaValue instanceof Date) { return this.tryCompareDate((Date) otherJavaValue); } else { throw new ExpressionRuntimeException("Could not compare " + this + " with " + other); } case Nil: return 1; //该分支未考虑this.lexeme为null的情况 default: throw new ExpressionRuntimeException("Could not compare " + this + " with " + other); } }
不知道我的理解是否正确,麻烦看一下这个问题,谢谢。
The text was updated successfully, but these errors were encountered:
这是个 bug,争取尽快修复下。
Sorry, something went wrong.
41c2f4b
(fix/feat) format code with google style and close #31
13c0ebd
已发布 3.1.1 , maven 仓库同步可能需要一到两天,感谢反馈。
8f2ef90
killme2008
No branches or pull requests
AviatorString类的compare方法未考虑this.lexeme为null以及otherString.lexeme为null的情况。这导致以下两种不符合预期的case
可能导致空指针异常的代码有以下两处
该代码在this.lexeme为null,或者otherString.lexeme为null时,均会抛出空指针异常。
下面是我用到的测试case
进行如下测试
附AviatorString的compare方法源码 (Aviator 3.0.0版本)
不知道我的理解是否正确,麻烦看一下这个问题,谢谢。
The text was updated successfully, but these errors were encountered: