Hi Elizaveta, Very good question.
For this, I created org.apache.beam.sdk.util.Preconditions.checkStateNotNull ( https://github.com/apache/beam/blob/1851eef15c5f455c95402ced50d757ea167d33d9/sdks/java/core/src/main/java/org/apache/beam/sdk/util/Preconditions.java#L450 ) Multiple reasons: - The annotations on this method are more useful than the ones in the equivalent Guava method. - The exception thrown is an IllegalStateException rather than NPE. Hope this helps! Kenn On Fri, Jun 17, 2022 at 11:30 AM Elizaveta Lomteva < [email protected]> wrote: > Hi community, > > I have a question about the compileJava check, null dereference warning. > > We use the checkState()/checkNotNull() methods instead of the if-else > statement to check that the variable is not null to follow the convention, > but this leads to a dereferencing warning for a possibly null reference. > > This is an example > > > > Could you please suggest what we should do in this case: > 1. leave the checkState()/checkNotNull() methods and suppress the > dereference of possibly-null reference warning; > 2. leave the if-else clause? > > What would you recommend? > > Thanks in advance, > Elizaveta > >
