union requires first member's default value

Default constructor of union type should initialize with the first
member. Java backend was failing with union types when their first member
is of enum type because enum type in Java backend is primitive but with
no default value. (To be specific, the generated default constructor was
trying to init primitive type(enum) with "null").

Now union's first member should have a useful default value.
- set explicit default value (e.g. int a = 3;)
- @nullable annotated.

So, when the first member of a union is an enum, it should have a
default value. Or, it will fail with an error.

Bug: 175834770
Test: aidl_unittests / aidl_integration_test
Change-Id: I6a0acc25331927826a8e747e6ea703f34dccae94
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index d894cb2..30b6abc 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -3852,6 +3852,16 @@
   EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr(expected_stderr));
 }
 
+TEST_P(AidlTest, UnionRejectsFirstEnumWithNoDefaults) {
+  import_paths_.insert(".");
+  io_delegate_.SetFileContents("a/Enum.aidl", "package a; enum Enum { FOO, BAR }");
+  const string expected_err = "The union's first member should have a useful default value.";
+  CaptureStderr();
+  EXPECT_EQ(nullptr,
+            Parse("a/Foo.aidl", "package a; union Foo { a.Enum e; }", typenames_, GetLanguage()));
+  EXPECT_THAT(GetCapturedStderr(), testing::HasSubstr(expected_err));
+}
+
 TEST_P(AidlTest, GenericStructuredParcelable) {
   io_delegate_.SetFileContents("Foo.aidl", "parcelable Foo<T, U> { int a; int A; }");
   Options options =