From 0599185fca7b66d6bea57f5d0d8fef2379a1bfac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Thu, 11 Mar 2021 07:37:58 -0800 Subject: [PATCH] [litho] Add test for replicating issue with null access path args Summary: This diff adds a test replicating the issue fixed in D26975222 (https://github.com/facebook/infer/commit/7110c1ca3f3db7d1b95edc021eee84cf77bbf0b0) in [commit 7110c1c](https://github.com/facebook/infer/commit/7110c1ca3f3db7d1b95edc021eee84cf77bbf0b0) Reviewed By: ngorogiannis Differential Revision: D26978562 fbshipit-source-id: 41e41df8c --- .../litho-required-props/RequiredProps.java | 18 ++++++++++++++++++ .../java/litho-required-props/issues.exp | 1 + 2 files changed, 19 insertions(+) diff --git a/infer/tests/codetoanalyze/java/litho-required-props/RequiredProps.java b/infer/tests/codetoanalyze/java/litho-required-props/RequiredProps.java index 065477039..4f0c79bc8 100644 --- a/infer/tests/codetoanalyze/java/litho-required-props/RequiredProps.java +++ b/infer/tests/codetoanalyze/java/litho-required-props/RequiredProps.java @@ -228,6 +228,24 @@ public class RequiredProps { builder.child(childBuilder); } + Component.Builder getBuilder(MyComponent.Builder builder) { + if (builder == null) { + return null; + } else { + return builder.prop1(new Object()); + } + } + + public void buildWithColumnChildBadNullOk() { + Column.Builder builder = Column.create(); + builder.child(getBuilder(null)); + } + + public void buildWithColumnChildBadCalleeBad() { + Column.Builder builder = Column.create(); + builder.child(getBuilder(mMyComponent.create())); + } + public Component buildWithColumnChildOk() { return Column.create() .child(mMyComponent.create().prop1(new Object()).prop3(new Object())) diff --git a/infer/tests/codetoanalyze/java/litho-required-props/issues.exp b/infer/tests/codetoanalyze/java/litho-required-props/issues.exp index d1c25f546..f26dac630 100644 --- a/infer/tests/codetoanalyze/java/litho-required-props/issues.exp +++ b/infer/tests/codetoanalyze/java/litho-required-props/issues.exp @@ -11,6 +11,7 @@ codetoanalyze/java/litho-required-props/RequiredProps.java, codetoanalyze.java.l codetoanalyze/java/litho-required-props/RequiredProps.java, codetoanalyze.java.litho.RequiredProps.buildPropResWithPxDoubleBad():void, 1, MISSING_REQUIRED_PROP, no_bucket, ERROR, [**@Prop propPx** is required for component codetoanalyze.java.litho.ResPropDoubleComponent, but is not set before the call to build(). Either set the missing @Prop or make @Prop(optional = true).,calls codetoanalyze.java.litho.ResPropDoubleComponent.create(...),calls prop(...)] codetoanalyze/java/litho-required-props/RequiredProps.java, codetoanalyze.java.litho.RequiredProps.buildPropVarArgMissingBad():void, 1, MISSING_REQUIRED_PROP, no_bucket, ERROR, [**Either @Prop props or @Prop(varArg = prop)** is required for component codetoanalyze.java.litho.VarArgPropComponent, but is not set before the call to build(). Either set the missing @Prop or make @Prop(optional = true).,calls codetoanalyze.java.litho.VarArgPropComponent.create(...)] codetoanalyze/java/litho-required-props/RequiredProps.java, codetoanalyze.java.litho.RequiredProps.buildWithColumnChildBad():void, 2, MISSING_REQUIRED_PROP, no_bucket, ERROR, [**@Prop prop3** is required for component codetoanalyze.java.litho.MyComponent, but is not set before the call to build(). Either set the missing @Prop or make @Prop(optional = true).,calls codetoanalyze.java.litho.MyComponent.create(...),calls prop1(...)] +codetoanalyze/java/litho-required-props/RequiredProps.java, codetoanalyze.java.litho.RequiredProps.buildWithColumnChildBadCalleeBad():void, 2, MISSING_REQUIRED_PROP, no_bucket, ERROR, [**@Prop prop3** is required for component codetoanalyze.java.litho.MyComponent, but is not set before the call to build(). Either set the missing @Prop or make @Prop(optional = true).,calls codetoanalyze.java.litho.MyComponent.create(...),calls prop1(...)] codetoanalyze/java/litho-required-props/RequiredProps.java, codetoanalyze.java.litho.RequiredProps.buildWithout1Bad():com.facebook.litho.Component, 1, MISSING_REQUIRED_PROP, no_bucket, ERROR, [**@Prop prop1** is required for component codetoanalyze.java.litho.MyComponent, but is not set before the call to build(). Either set the missing @Prop or make @Prop(optional = true).,calls codetoanalyze.java.litho.MyComponent.create(...),calls prop2(...),calls prop3(...)] codetoanalyze/java/litho-required-props/RequiredProps.java, codetoanalyze.java.litho.RequiredProps.buildWithout3Bad():com.facebook.litho.Component, 1, MISSING_REQUIRED_PROP, no_bucket, ERROR, [**@Prop prop3** is required for component codetoanalyze.java.litho.MyComponent, but is not set before the call to build(). Either set the missing @Prop or make @Prop(optional = true).,calls codetoanalyze.java.litho.MyComponent.create(...),calls prop1(...),calls prop2(...)] codetoanalyze/java/litho-required-props/RequiredProps.java, codetoanalyze.java.litho.RequiredProps.callBuildSuffixWithoutRequiredBad():com.facebook.litho.Component, 1, MISSING_REQUIRED_PROP, no_bucket, ERROR, [**@Prop prop1** is required for component codetoanalyze.java.litho.MyComponent, but is not set before the call to build(). Either set the missing @Prop or make @Prop(optional = true).,calls codetoanalyze.java.litho.MyComponent.create(...),calls prop2(...),calls prop3(...)]