Skip to content
New issue

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

期望OperateDataField取值时增加空判断,防止获取不存在的属性时报NPE错误 #165

Open
haogrgr opened this issue Dec 13, 2021 · 0 comments

Comments

@haogrgr
Copy link

haogrgr commented Dec 13, 2021

描述:OperateDataField.getObjectInner方法内部通过反射来获取对象属性,当属性不存在时,会报NPE错误。
代码:

@Test
public void transform() throws Exception {
    QLExpressRunStrategy.setAvoidNullPointer(true);
    ExpressRunner runner = new ExpressRunner(true, false);

    DefaultContext<String, Object> context = new DefaultContext<>();
    context.put("target", TestVO.of(1L));
    Object ret = runner.execute("target.name", context, null, true, false, 60000L);

    System.out.println(ret);
}

@Data
@RequiredArgsConstructor(staticName = "of")
public static class TestVO {
    private final Long id;
}

错误:

java.lang.RuntimeException: java.lang.NullPointerException
at com.ql.util.express.ExpressUtil.getPropertyClass(ExpressUtil.java:573)
Caused by: java.lang.NullPointerException
at com.ql.util.express.ExpressUtil.getPropertyClass(ExpressUtil.java:570)
... 30 more

期望:
希望当获取不存在的属性时,如果AvoidNullPointer设置为为TRUE,则直接返回null,而不是报错。

@haogrgr haogrgr changed the title 期望新增OperateDataField增加空判断,防止获取不存在的属性时报NPE错误 期望OperateDataField取值时增加空判断,防止获取不存在的属性时报NPE错误 Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant