From 8bfafc76deb884b2d5110373c0df9fc0ac38b7db Mon Sep 17 00:00:00 2001 From: Jacek Surazski Date: Thu, 17 Oct 2019 15:23:15 -0700 Subject: [PATCH] Java: Don't annotate vector-of-tables item getters with @nullable. (#5562) * Annotate getters with @Pure when --java-checkerframework is specified. Together with @Nullable, this allows users to use static analysis tools like CheckerFramework to catch NPEs caused by unset fields. * Don't annotate vector-of-tables item getters with @Nullable. Since Flatbuffers don't support null items in vectors of tables. --- src/idl_gen_general.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp index 47e035b8b..30564bf84 100644 --- a/src/idl_gen_general.cpp +++ b/src/idl_gen_general.cpp @@ -252,7 +252,8 @@ class GeneralGenerator : public BaseGenerator { std::string GenNullableAnnotation(const Type &t) const { return lang_.language == IDLOptions::kJava && parser_.opts.gen_nullable && - !IsScalar(DestinationType(t, true).base_type) + !IsScalar(DestinationType(t, true).base_type) && + t.base_type != BASE_TYPE_VECTOR ? " @Nullable " : ""; }