From 4dfa3be87191afeb82b695e7f9e94c7129c51ff3 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Mon, 19 Oct 2020 09:31:22 -0700 Subject: [PATCH] Codegen Android: handle nullable getConstants() properties generation. Summary: The GenerateModuleJavaSpec.js mistakenly treated nullable getConstants() properties as required, such that the Java spec will throw an exception when the properties are missing. This fixed it. Note that the JavaPoet-based generator got this correct already. Changelog: [Internal] Differential Revision: D24381941 fbshipit-source-id: c95d2181c66443e2191318f09b6454a5296009e4 --- .../src/generators/modules/GenerateModuleJavaSpec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js index 8a35a0b5061..2b263a04642 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js @@ -203,8 +203,7 @@ function buildGetConstantsMethod( const rawProperties = methodTypeAnnotation.returnTypeAnnotation.properties || []; rawProperties.forEach(p => { - // TODO(T76712813): Should we push to optionalProps if the constant is nullable? - if (p.optional) { + if (p.optional || p.typeAnnotation.type === 'NullableTypeAnnotation') { optionalProps.push(p.name); } else { requiredProps.push(p.name);