This is an automated email from the ASF dual-hosted git repository.

opwvhk pushed a commit to branch branch-1.12
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 1eed38fbb880ce0ab6f2d278d242c898b1512e5e
Author: Sivaprasanna <[email protected]>
AuthorDate: Tue Jun 10 08:18:27 2025 +0200

    AVRO-4133: Support default enum value in Protobuf to Avro (#3367)
    
    * [AVRO-4133] Support default enum value in Protobuf to Avro
    
    * [AVRO-4133] Add unit test for proto schema enum default
    
    * [AVRO-4133] Exclude generated test proto code
    
    ---------
    
    Co-authored-by: sivaprasanna <[email protected]>
    (cherry picked from commit 5f7c2d36c72c08e3da5fa5f7be595841b4ef5c88)
---
 lang/java/protobuf/pom.xml                         |   4 +
 .../org/apache/avro/protobuf/ProtobufData.java     |  16 +-
 .../org/apache/avro/protobuf/TestProtobuf.java     |  14 +
 .../org/apache/avro/protobuf/noopt/TestProto3.java | 883 +++++++++++++++++++++
 lang/java/protobuf/src/test/protobuf/test.proto    |   2 +
 .../protobuf/src/test/protobuf/test_proto3.proto   |  33 +
 pom.xml                                            |   1 +
 7 files changed, 951 insertions(+), 2 deletions(-)

diff --git a/lang/java/protobuf/pom.xml b/lang/java/protobuf/pom.xml
index 2e4902d1c5..1b981f9a1d 100644
--- a/lang/java/protobuf/pom.xml
+++ b/lang/java/protobuf/pom.xml
@@ -65,6 +65,10 @@
                       <arg value="--java_out=src/test/java/"/>
                       <arg 
value="src/test/protobuf/test_multiple_files.proto"/>
                     </exec>
+                    <exec executable="protoc">
+                      <arg value="--java_out=src/test/java/"/>
+                      <arg value="src/test/protobuf/test_proto3.proto"/>
+                    </exec>
                   </target>
                 </configuration>
                 <goals>
diff --git 
a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java 
b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
index ca4d78b602..f75a7cc359 100644
--- 
a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
+++ 
b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
@@ -301,7 +301,8 @@ public class ProtobufData extends GenericData {
     case SFIXED64:
       return Schema.create(Schema.Type.LONG);
     case ENUM:
-      return getSchema(f.getEnumType());
+      return f.hasDefaultValue() ? getSchema(f.getEnumType(), 
((EnumValueDescriptor) f.getDefaultValue()).getName())
+          : getSchema(f.getEnumType());
     case MESSAGE:
       result = getSchema(f.getMessageType());
       if (f.isOptional())
@@ -315,11 +316,22 @@ public class ProtobufData extends GenericData {
   }
 
   public Schema getSchema(EnumDescriptor d) {
+    List<String> symbols = getEnumSymbols(d);
+    String enumDefault = symbols.isEmpty() ? null : symbols.get(0);
+    return Schema.createEnum(d.getName(), null, getNamespace(d.getFile(), 
d.getContainingType()), symbols, enumDefault);
+  }
+
+  public Schema getSchema(EnumDescriptor d, String enumDefault) {
+    List<String> symbols = getEnumSymbols(d);
+    return Schema.createEnum(d.getName(), null, getNamespace(d.getFile(), 
d.getContainingType()), symbols, enumDefault);
+  }
+
+  private List<String> getEnumSymbols(EnumDescriptor d) {
     List<String> symbols = new ArrayList<>(d.getValues().size());
     for (EnumValueDescriptor e : d.getValues()) {
       symbols.add(e.getName());
     }
-    return Schema.createEnum(d.getName(), null, getNamespace(d.getFile(), 
d.getContainingType()), symbols);
+    return symbols;
   }
 
   private static final JsonFactory FACTORY = new JsonFactory();
diff --git 
a/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/TestProtobuf.java 
b/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/TestProtobuf.java
index 5ac34fdae6..c45f85ce83 100644
--- 
a/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/TestProtobuf.java
+++ 
b/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/TestProtobuf.java
@@ -24,6 +24,7 @@ import org.apache.avro.Schema;
 import org.apache.avro.io.DecoderFactory;
 import org.apache.avro.io.Encoder;
 import org.apache.avro.io.EncoderFactory;
+import org.apache.avro.protobuf.noopt.TestProto3;
 import org.apache.avro.specific.SpecificData;
 import org.apache.commons.compress.utils.Lists;
 import org.junit.jupiter.api.Test;
@@ -146,4 +147,17 @@ public class TestProtobuf {
     Schema s2 = instance2.getSchema(com.google.protobuf.Timestamp.class);
     assertEquals(conversion.getRecommendedSchema(), s2);
   }
+
+  @Test
+  void enumDefault() {
+    Schema fooSchema = ProtobufData.get().getSchema(Foo.class);
+    assertEquals("Z", fooSchema.getField("enum").schema().getEnumDefault());
+
+    Schema nSchema = ProtobufData.get().getSchema(N.class);
+    assertEquals("A", nSchema.getEnumDefault());
+
+    Schema proto3Schema = ProtobufData.get().getSchema(TestProto3.User.class);
+    assertEquals("STATUS_UNKNOWN", 
proto3Schema.getField("status").defaultVal());
+    assertEquals("STATUS_UNKNOWN", 
proto3Schema.getField("status").schema().getEnumDefault());
+  }
 }
diff --git 
a/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/noopt/TestProto3.java
 
b/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/noopt/TestProto3.java
new file mode 100644
index 0000000000..9255cc50f5
--- /dev/null
+++ 
b/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/noopt/TestProto3.java
@@ -0,0 +1,883 @@
+// Generated by the protocol buffer compiler.  DO NOT EDIT!
+// NO CHECKED-IN PROTOBUF GENCODE
+// source: src/test/protobuf/test_proto3.proto
+// Protobuf Java Version: 4.29.3
+
+package org.apache.avro.protobuf.noopt;
+
+public final class TestProto3 {
+  private TestProto3() {
+  }
+
+  static {
+    com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(
+        com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= */ 
4, /* minor= */ 29, /* patch= */ 3,
+        /* suffix= */ "", TestProto3.class.getName());
+  }
+
+  public static void 
registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {
+  }
+
+  public static void 
registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) {
+    registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) 
registry);
+  }
+
+  /**
+   * Protobuf enum {@code org.apache.avro.protobuf.noopt.Status}
+   */
+  public enum Status implements com.google.protobuf.ProtocolMessageEnum {
+    /**
+     * <code>STATUS_UNKNOWN = 0;</code>
+     */
+    STATUS_UNKNOWN(0),
+    /**
+     * <code>STATUS_ACTIVE = 1;</code>
+     */
+    STATUS_ACTIVE(1),
+    /**
+     * <code>STATUS_INACTIVE = 2;</code>
+     */
+    STATUS_INACTIVE(2), UNRECOGNIZED(-1),;
+
+    static {
+      com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(
+          com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= 
*/ 4, /* minor= */ 29, /* patch= */ 3,
+          /* suffix= */ "", Status.class.getName());
+    }
+    /**
+     * <code>STATUS_UNKNOWN = 0;</code>
+     */
+    public static final int STATUS_UNKNOWN_VALUE = 0;
+    /**
+     * <code>STATUS_ACTIVE = 1;</code>
+     */
+    public static final int STATUS_ACTIVE_VALUE = 1;
+    /**
+     * <code>STATUS_INACTIVE = 2;</code>
+     */
+    public static final int STATUS_INACTIVE_VALUE = 2;
+
+    public final int getNumber() {
+      if (this == UNRECOGNIZED) {
+        throw new java.lang.IllegalArgumentException("Can't get the number of 
an unknown enum value.");
+      }
+      return value;
+    }
+
+    /**
+     * @param value The numeric wire value of the corresponding enum entry.
+     * @return The enum associated with the given numeric wire value.
+     * @deprecated Use {@link #forNumber(int)} instead.
+     */
+    @java.lang.Deprecated
+    public static Status valueOf(int value) {
+      return forNumber(value);
+    }
+
+    /**
+     * @param value The numeric wire value of the corresponding enum entry.
+     * @return The enum associated with the given numeric wire value.
+     */
+    public static Status forNumber(int value) {
+      switch (value) {
+      case 0:
+        return STATUS_UNKNOWN;
+      case 1:
+        return STATUS_ACTIVE;
+      case 2:
+        return STATUS_INACTIVE;
+      default:
+        return null;
+      }
+    }
+
+    public static com.google.protobuf.Internal.EnumLiteMap<Status> 
internalGetValueMap() {
+      return internalValueMap;
+    }
+
+    private static final com.google.protobuf.Internal.EnumLiteMap<Status> 
internalValueMap = new com.google.protobuf.Internal.EnumLiteMap<Status>() {
+      public Status findValueByNumber(int number) {
+        return Status.forNumber(number);
+      }
+    };
+
+    public final com.google.protobuf.Descriptors.EnumValueDescriptor 
getValueDescriptor() {
+      if (this == UNRECOGNIZED) {
+        throw new java.lang.IllegalStateException("Can't get the descriptor of 
an unrecognized enum value.");
+      }
+      return getDescriptor().getValues().get(ordinal());
+    }
+
+    public final com.google.protobuf.Descriptors.EnumDescriptor 
getDescriptorForType() {
+      return getDescriptor();
+    }
+
+    public static final com.google.protobuf.Descriptors.EnumDescriptor 
getDescriptor() {
+      return 
org.apache.avro.protobuf.noopt.TestProto3.getDescriptor().getEnumTypes().get(0);
+    }
+
+    private static final Status[] VALUES = values();
+
+    public static Status 
valueOf(com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
+      if (desc.getType() != getDescriptor()) {
+        throw new java.lang.IllegalArgumentException("EnumValueDescriptor is 
not for this type.");
+      }
+      if (desc.getIndex() == -1) {
+        return UNRECOGNIZED;
+      }
+      return VALUES[desc.getIndex()];
+    }
+
+    private final int value;
+
+    private Status(int value) {
+      this.value = value;
+    }
+
+    // 
@@protoc_insertion_point(enum_scope:org.apache.avro.protobuf.noopt.Status)
+  }
+
+  public interface UserOrBuilder extends
+      // 
@@protoc_insertion_point(interface_extends:org.apache.avro.protobuf.noopt.User)
+      com.google.protobuf.MessageOrBuilder {
+
+    /**
+     * <code>string name = 1;</code>
+     * 
+     * @return The name.
+     */
+    java.lang.String getName();
+
+    /**
+     * <code>string name = 1;</code>
+     * 
+     * @return The bytes for name.
+     */
+    com.google.protobuf.ByteString getNameBytes();
+
+    /**
+     * <code>int32 id = 2;</code>
+     * 
+     * @return The id.
+     */
+    int getId();
+
+    /**
+     * <code>.org.apache.avro.protobuf.noopt.Status status = 3;</code>
+     * 
+     * @return The enum numeric value on the wire for status.
+     */
+    int getStatusValue();
+
+    /**
+     * <code>.org.apache.avro.protobuf.noopt.Status status = 3;</code>
+     * 
+     * @return The status.
+     */
+    org.apache.avro.protobuf.noopt.TestProto3.Status getStatus();
+  }
+
+  /**
+   * Protobuf type {@code org.apache.avro.protobuf.noopt.User}
+   */
+  public static final class User extends com.google.protobuf.GeneratedMessage 
implements
+      // 
@@protoc_insertion_point(message_implements:org.apache.avro.protobuf.noopt.User)
+      UserOrBuilder {
+    private static final long serialVersionUID = 0L;
+    static {
+      com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(
+          com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC, /* major= 
*/ 4, /* minor= */ 29, /* patch= */ 3,
+          /* suffix= */ "", User.class.getName());
+    }
+
+    // Use User.newBuilder() to construct.
+    private User(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
+      super(builder);
+    }
+
+    private User() {
+      name_ = "";
+      status_ = 0;
+    }
+
+    public static final com.google.protobuf.Descriptors.Descriptor 
getDescriptor() {
+      return 
org.apache.avro.protobuf.noopt.TestProto3.internal_static_org_apache_avro_protobuf_noopt_User_descriptor;
+    }
+
+    @java.lang.Override
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 
internalGetFieldAccessorTable() {
+      return 
org.apache.avro.protobuf.noopt.TestProto3.internal_static_org_apache_avro_protobuf_noopt_User_fieldAccessorTable
+          
.ensureFieldAccessorsInitialized(org.apache.avro.protobuf.noopt.TestProto3.User.class,
+              org.apache.avro.protobuf.noopt.TestProto3.User.Builder.class);
+    }
+
+    public static final int NAME_FIELD_NUMBER = 1;
+    @SuppressWarnings("serial")
+    private volatile java.lang.Object name_ = "";
+
+    /**
+     * <code>string name = 1;</code>
+     * 
+     * @return The name.
+     */
+    @java.lang.Override
+    public java.lang.String getName() {
+      java.lang.Object ref = name_;
+      if (ref instanceof java.lang.String) {
+        return (java.lang.String) ref;
+      } else {
+        com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) 
ref;
+        java.lang.String s = bs.toStringUtf8();
+        name_ = s;
+        return s;
+      }
+    }
+
+    /**
+     * <code>string name = 1;</code>
+     * 
+     * @return The bytes for name.
+     */
+    @java.lang.Override
+    public com.google.protobuf.ByteString getNameBytes() {
+      java.lang.Object ref = name_;
+      if (ref instanceof java.lang.String) {
+        com.google.protobuf.ByteString b = 
com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
+        name_ = b;
+        return b;
+      } else {
+        return (com.google.protobuf.ByteString) ref;
+      }
+    }
+
+    public static final int ID_FIELD_NUMBER = 2;
+    private int id_ = 0;
+
+    /**
+     * <code>int32 id = 2;</code>
+     * 
+     * @return The id.
+     */
+    @java.lang.Override
+    public int getId() {
+      return id_;
+    }
+
+    public static final int STATUS_FIELD_NUMBER = 3;
+    private int status_ = 0;
+
+    /**
+     * <code>.org.apache.avro.protobuf.noopt.Status status = 3;</code>
+     * 
+     * @return The enum numeric value on the wire for status.
+     */
+    @java.lang.Override
+    public int getStatusValue() {
+      return status_;
+    }
+
+    /**
+     * <code>.org.apache.avro.protobuf.noopt.Status status = 3;</code>
+     * 
+     * @return The status.
+     */
+    @java.lang.Override
+    public org.apache.avro.protobuf.noopt.TestProto3.Status getStatus() {
+      org.apache.avro.protobuf.noopt.TestProto3.Status result = 
org.apache.avro.protobuf.noopt.TestProto3.Status
+          .forNumber(status_);
+      return result == null ? 
org.apache.avro.protobuf.noopt.TestProto3.Status.UNRECOGNIZED : result;
+    }
+
+    private byte memoizedIsInitialized = -1;
+
+    @java.lang.Override
+    public final boolean isInitialized() {
+      byte isInitialized = memoizedIsInitialized;
+      if (isInitialized == 1)
+        return true;
+      if (isInitialized == 0)
+        return false;
+
+      memoizedIsInitialized = 1;
+      return true;
+    }
+
+    @java.lang.Override
+    public void writeTo(com.google.protobuf.CodedOutputStream output) throws 
java.io.IOException {
+      if (!com.google.protobuf.GeneratedMessage.isStringEmpty(name_)) {
+        com.google.protobuf.GeneratedMessage.writeString(output, 1, name_);
+      }
+      if (id_ != 0) {
+        output.writeInt32(2, id_);
+      }
+      if (status_ != 
org.apache.avro.protobuf.noopt.TestProto3.Status.STATUS_UNKNOWN.getNumber()) {
+        output.writeEnum(3, status_);
+      }
+      getUnknownFields().writeTo(output);
+    }
+
+    @java.lang.Override
+    public int getSerializedSize() {
+      int size = memoizedSize;
+      if (size != -1)
+        return size;
+
+      size = 0;
+      if (!com.google.protobuf.GeneratedMessage.isStringEmpty(name_)) {
+        size += com.google.protobuf.GeneratedMessage.computeStringSize(1, 
name_);
+      }
+      if (id_ != 0) {
+        size += com.google.protobuf.CodedOutputStream.computeInt32Size(2, id_);
+      }
+      if (status_ != 
org.apache.avro.protobuf.noopt.TestProto3.Status.STATUS_UNKNOWN.getNumber()) {
+        size += com.google.protobuf.CodedOutputStream.computeEnumSize(3, 
status_);
+      }
+      size += getUnknownFields().getSerializedSize();
+      memoizedSize = size;
+      return size;
+    }
+
+    @java.lang.Override
+    public boolean equals(final java.lang.Object obj) {
+      if (obj == this) {
+        return true;
+      }
+      if (!(obj instanceof org.apache.avro.protobuf.noopt.TestProto3.User)) {
+        return super.equals(obj);
+      }
+      org.apache.avro.protobuf.noopt.TestProto3.User other = 
(org.apache.avro.protobuf.noopt.TestProto3.User) obj;
+
+      if (!getName().equals(other.getName()))
+        return false;
+      if (getId() != other.getId())
+        return false;
+      if (status_ != other.status_)
+        return false;
+      if (!getUnknownFields().equals(other.getUnknownFields()))
+        return false;
+      return true;
+    }
+
+    @java.lang.Override
+    public int hashCode() {
+      if (memoizedHashCode != 0) {
+        return memoizedHashCode;
+      }
+      int hash = 41;
+      hash = (19 * hash) + getDescriptor().hashCode();
+      hash = (37 * hash) + NAME_FIELD_NUMBER;
+      hash = (53 * hash) + getName().hashCode();
+      hash = (37 * hash) + ID_FIELD_NUMBER;
+      hash = (53 * hash) + getId();
+      hash = (37 * hash) + STATUS_FIELD_NUMBER;
+      hash = (53 * hash) + status_;
+      hash = (29 * hash) + getUnknownFields().hashCode();
+      memoizedHashCode = hash;
+      return hash;
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseFrom(java.nio.ByteBuffer data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseFrom(java.nio.ByteBuffer data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data, extensionRegistry);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseFrom(com.google.protobuf.ByteString data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseFrom(com.google.protobuf.ByteString data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data, extensionRegistry);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseFrom(byte[] data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseFrom(byte[] data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data, extensionRegistry);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, 
input);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseFrom(java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws 
java.io.IOException {
+      return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, 
input, extensionRegistry);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseDelimitedFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return 
com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException(PARSER, 
input);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseDelimitedFrom(java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws 
java.io.IOException {
+      return 
com.google.protobuf.GeneratedMessage.parseDelimitedWithIOException(PARSER, 
input, extensionRegistry);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseFrom(com.google.protobuf.CodedInputStream input)
+        throws java.io.IOException {
+      return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, 
input);
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
parseFrom(com.google.protobuf.CodedInputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws 
java.io.IOException {
+      return com.google.protobuf.GeneratedMessage.parseWithIOException(PARSER, 
input, extensionRegistry);
+    }
+
+    @java.lang.Override
+    public Builder newBuilderForType() {
+      return newBuilder();
+    }
+
+    public static Builder newBuilder() {
+      return DEFAULT_INSTANCE.toBuilder();
+    }
+
+    public static Builder 
newBuilder(org.apache.avro.protobuf.noopt.TestProto3.User prototype) {
+      return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
+    }
+
+    @java.lang.Override
+    public Builder toBuilder() {
+      return this == DEFAULT_INSTANCE ? new Builder() : new 
Builder().mergeFrom(this);
+    }
+
+    @java.lang.Override
+    protected Builder 
newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+      Builder builder = new Builder(parent);
+      return builder;
+    }
+
+    /**
+     * Protobuf type {@code org.apache.avro.protobuf.noopt.User}
+     */
+    public static final class Builder extends 
com.google.protobuf.GeneratedMessage.Builder<Builder> implements
+        // 
@@protoc_insertion_point(builder_implements:org.apache.avro.protobuf.noopt.User)
+        org.apache.avro.protobuf.noopt.TestProto3.UserOrBuilder {
+      public static final com.google.protobuf.Descriptors.Descriptor 
getDescriptor() {
+        return 
org.apache.avro.protobuf.noopt.TestProto3.internal_static_org_apache_avro_protobuf_noopt_User_descriptor;
+      }
+
+      @java.lang.Override
+      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 
internalGetFieldAccessorTable() {
+        return 
org.apache.avro.protobuf.noopt.TestProto3.internal_static_org_apache_avro_protobuf_noopt_User_fieldAccessorTable
+            
.ensureFieldAccessorsInitialized(org.apache.avro.protobuf.noopt.TestProto3.User.class,
+                org.apache.avro.protobuf.noopt.TestProto3.User.Builder.class);
+      }
+
+      // Construct using 
org.apache.avro.protobuf.noopt.TestProto3.User.newBuilder()
+      private Builder() {
+
+      }
+
+      private Builder(com.google.protobuf.GeneratedMessage.BuilderParent 
parent) {
+        super(parent);
+
+      }
+
+      @java.lang.Override
+      public Builder clear() {
+        super.clear();
+        bitField0_ = 0;
+        name_ = "";
+        id_ = 0;
+        status_ = 0;
+        return this;
+      }
+
+      @java.lang.Override
+      public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() 
{
+        return 
org.apache.avro.protobuf.noopt.TestProto3.internal_static_org_apache_avro_protobuf_noopt_User_descriptor;
+      }
+
+      @java.lang.Override
+      public org.apache.avro.protobuf.noopt.TestProto3.User 
getDefaultInstanceForType() {
+        return 
org.apache.avro.protobuf.noopt.TestProto3.User.getDefaultInstance();
+      }
+
+      @java.lang.Override
+      public org.apache.avro.protobuf.noopt.TestProto3.User build() {
+        org.apache.avro.protobuf.noopt.TestProto3.User result = buildPartial();
+        if (!result.isInitialized()) {
+          throw newUninitializedMessageException(result);
+        }
+        return result;
+      }
+
+      @java.lang.Override
+      public org.apache.avro.protobuf.noopt.TestProto3.User buildPartial() {
+        org.apache.avro.protobuf.noopt.TestProto3.User result = new 
org.apache.avro.protobuf.noopt.TestProto3.User(
+            this);
+        if (bitField0_ != 0) {
+          buildPartial0(result);
+        }
+        onBuilt();
+        return result;
+      }
+
+      private void 
buildPartial0(org.apache.avro.protobuf.noopt.TestProto3.User result) {
+        int from_bitField0_ = bitField0_;
+        if (((from_bitField0_ & 0x00000001) != 0)) {
+          result.name_ = name_;
+        }
+        if (((from_bitField0_ & 0x00000002) != 0)) {
+          result.id_ = id_;
+        }
+        if (((from_bitField0_ & 0x00000004) != 0)) {
+          result.status_ = status_;
+        }
+      }
+
+      @java.lang.Override
+      public Builder mergeFrom(com.google.protobuf.Message other) {
+        if (other instanceof org.apache.avro.protobuf.noopt.TestProto3.User) {
+          return mergeFrom((org.apache.avro.protobuf.noopt.TestProto3.User) 
other);
+        } else {
+          super.mergeFrom(other);
+          return this;
+        }
+      }
+
+      public Builder mergeFrom(org.apache.avro.protobuf.noopt.TestProto3.User 
other) {
+        if (other == 
org.apache.avro.protobuf.noopt.TestProto3.User.getDefaultInstance())
+          return this;
+        if (!other.getName().isEmpty()) {
+          name_ = other.name_;
+          bitField0_ |= 0x00000001;
+          onChanged();
+        }
+        if (other.getId() != 0) {
+          setId(other.getId());
+        }
+        if (other.status_ != 0) {
+          setStatusValue(other.getStatusValue());
+        }
+        this.mergeUnknownFields(other.getUnknownFields());
+        onChanged();
+        return this;
+      }
+
+      @java.lang.Override
+      public final boolean isInitialized() {
+        return true;
+      }
+
+      @java.lang.Override
+      public Builder mergeFrom(com.google.protobuf.CodedInputStream input,
+          com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws 
java.io.IOException {
+        if (extensionRegistry == null) {
+          throw new java.lang.NullPointerException();
+        }
+        try {
+          boolean done = false;
+          while (!done) {
+            int tag = input.readTag();
+            switch (tag) {
+            case 0:
+              done = true;
+              break;
+            case 10: {
+              name_ = input.readStringRequireUtf8();
+              bitField0_ |= 0x00000001;
+              break;
+            } // case 10
+            case 16: {
+              id_ = input.readInt32();
+              bitField0_ |= 0x00000002;
+              break;
+            } // case 16
+            case 24: {
+              status_ = input.readEnum();
+              bitField0_ |= 0x00000004;
+              break;
+            } // case 24
+            default: {
+              if (!super.parseUnknownField(input, extensionRegistry, tag)) {
+                done = true; // was an endgroup tag
+              }
+              break;
+            } // default:
+            } // switch (tag)
+          } // while (!done)
+        } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+          throw e.unwrapIOException();
+        } finally {
+          onChanged();
+        } // finally
+        return this;
+      }
+
+      private int bitField0_;
+
+      private java.lang.Object name_ = "";
+
+      /**
+       * <code>string name = 1;</code>
+       * 
+       * @return The name.
+       */
+      public java.lang.String getName() {
+        java.lang.Object ref = name_;
+        if (!(ref instanceof java.lang.String)) {
+          com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) 
ref;
+          java.lang.String s = bs.toStringUtf8();
+          name_ = s;
+          return s;
+        } else {
+          return (java.lang.String) ref;
+        }
+      }
+
+      /**
+       * <code>string name = 1;</code>
+       * 
+       * @return The bytes for name.
+       */
+      public com.google.protobuf.ByteString getNameBytes() {
+        java.lang.Object ref = name_;
+        if (ref instanceof String) {
+          com.google.protobuf.ByteString b = 
com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
+          name_ = b;
+          return b;
+        } else {
+          return (com.google.protobuf.ByteString) ref;
+        }
+      }
+
+      /**
+       * <code>string name = 1;</code>
+       * 
+       * @param value The name to set.
+       * @return This builder for chaining.
+       */
+      public Builder setName(java.lang.String value) {
+        if (value == null) {
+          throw new NullPointerException();
+        }
+        name_ = value;
+        bitField0_ |= 0x00000001;
+        onChanged();
+        return this;
+      }
+
+      /**
+       * <code>string name = 1;</code>
+       * 
+       * @return This builder for chaining.
+       */
+      public Builder clearName() {
+        name_ = getDefaultInstance().getName();
+        bitField0_ = (bitField0_ & ~0x00000001);
+        onChanged();
+        return this;
+      }
+
+      /**
+       * <code>string name = 1;</code>
+       * 
+       * @param value The bytes for name to set.
+       * @return This builder for chaining.
+       */
+      public Builder setNameBytes(com.google.protobuf.ByteString value) {
+        if (value == null) {
+          throw new NullPointerException();
+        }
+        checkByteStringIsUtf8(value);
+        name_ = value;
+        bitField0_ |= 0x00000001;
+        onChanged();
+        return this;
+      }
+
+      private int id_;
+
+      /**
+       * <code>int32 id = 2;</code>
+       * 
+       * @return The id.
+       */
+      @java.lang.Override
+      public int getId() {
+        return id_;
+      }
+
+      /**
+       * <code>int32 id = 2;</code>
+       * 
+       * @param value The id to set.
+       * @return This builder for chaining.
+       */
+      public Builder setId(int value) {
+
+        id_ = value;
+        bitField0_ |= 0x00000002;
+        onChanged();
+        return this;
+      }
+
+      /**
+       * <code>int32 id = 2;</code>
+       * 
+       * @return This builder for chaining.
+       */
+      public Builder clearId() {
+        bitField0_ = (bitField0_ & ~0x00000002);
+        id_ = 0;
+        onChanged();
+        return this;
+      }
+
+      private int status_ = 0;
+
+      /**
+       * <code>.org.apache.avro.protobuf.noopt.Status status = 3;</code>
+       * 
+       * @return The enum numeric value on the wire for status.
+       */
+      @java.lang.Override
+      public int getStatusValue() {
+        return status_;
+      }
+
+      /**
+       * <code>.org.apache.avro.protobuf.noopt.Status status = 3;</code>
+       * 
+       * @param value The enum numeric value on the wire for status to set.
+       * @return This builder for chaining.
+       */
+      public Builder setStatusValue(int value) {
+        status_ = value;
+        bitField0_ |= 0x00000004;
+        onChanged();
+        return this;
+      }
+
+      /**
+       * <code>.org.apache.avro.protobuf.noopt.Status status = 3;</code>
+       * 
+       * @return The status.
+       */
+      @java.lang.Override
+      public org.apache.avro.protobuf.noopt.TestProto3.Status getStatus() {
+        org.apache.avro.protobuf.noopt.TestProto3.Status result = 
org.apache.avro.protobuf.noopt.TestProto3.Status
+            .forNumber(status_);
+        return result == null ? 
org.apache.avro.protobuf.noopt.TestProto3.Status.UNRECOGNIZED : result;
+      }
+
+      /**
+       * <code>.org.apache.avro.protobuf.noopt.Status status = 3;</code>
+       * 
+       * @param value The status to set.
+       * @return This builder for chaining.
+       */
+      public Builder 
setStatus(org.apache.avro.protobuf.noopt.TestProto3.Status value) {
+        if (value == null) {
+          throw new NullPointerException();
+        }
+        bitField0_ |= 0x00000004;
+        status_ = value.getNumber();
+        onChanged();
+        return this;
+      }
+
+      /**
+       * <code>.org.apache.avro.protobuf.noopt.Status status = 3;</code>
+       * 
+       * @return This builder for chaining.
+       */
+      public Builder clearStatus() {
+        bitField0_ = (bitField0_ & ~0x00000004);
+        status_ = 0;
+        onChanged();
+        return this;
+      }
+
+      // 
@@protoc_insertion_point(builder_scope:org.apache.avro.protobuf.noopt.User)
+    }
+
+    // 
@@protoc_insertion_point(class_scope:org.apache.avro.protobuf.noopt.User)
+    private static final org.apache.avro.protobuf.noopt.TestProto3.User 
DEFAULT_INSTANCE;
+    static {
+      DEFAULT_INSTANCE = new org.apache.avro.protobuf.noopt.TestProto3.User();
+    }
+
+    public static org.apache.avro.protobuf.noopt.TestProto3.User 
getDefaultInstance() {
+      return DEFAULT_INSTANCE;
+    }
+
+    private static final com.google.protobuf.Parser<User> PARSER = new 
com.google.protobuf.AbstractParser<User>() {
+      @java.lang.Override
+      public User parsePartialFrom(com.google.protobuf.CodedInputStream input,
+          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+          throws com.google.protobuf.InvalidProtocolBufferException {
+        Builder builder = newBuilder();
+        try {
+          builder.mergeFrom(input, extensionRegistry);
+        } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+          throw e.setUnfinishedMessage(builder.buildPartial());
+        } catch (com.google.protobuf.UninitializedMessageException e) {
+          throw 
e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial());
+        } catch (java.io.IOException e) {
+          throw new 
com.google.protobuf.InvalidProtocolBufferException(e).setUnfinishedMessage(builder.buildPartial());
+        }
+        return builder.buildPartial();
+      }
+    };
+
+    public static com.google.protobuf.Parser<User> parser() {
+      return PARSER;
+    }
+
+    @java.lang.Override
+    public com.google.protobuf.Parser<User> getParserForType() {
+      return PARSER;
+    }
+
+    @java.lang.Override
+    public org.apache.avro.protobuf.noopt.TestProto3.User 
getDefaultInstanceForType() {
+      return DEFAULT_INSTANCE;
+    }
+
+  }
+
+  private static final com.google.protobuf.Descriptors.Descriptor 
internal_static_org_apache_avro_protobuf_noopt_User_descriptor;
+  private static final com.google.protobuf.GeneratedMessage.FieldAccessorTable 
internal_static_org_apache_avro_protobuf_noopt_User_fieldAccessorTable;
+
+  public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() 
{
+    return descriptor;
+  }
+
+  private static com.google.protobuf.Descriptors.FileDescriptor descriptor;
+  static {
+    java.lang.String[] descriptorData = {
+        "\n#src/test/protobuf/test_proto3.proto\022\036o" + 
"rg.apache.avro.protobuf.noopt\"X\n\004User\022\014\n"
+            + "\004name\030\001 \001(\t\022\n\n\002id\030\002 
\001(\005\0226\n\006status\030\003 \001(\0162"
+            + "&.org.apache.avro.protobuf.noopt.Status*"
+            + 
"D\n\006Status\022\022\n\016STATUS_UNKNOWN\020\000\022\021\n\rSTATUS_"
+            + "ACTIVE\020\001\022\023\n\017STATUS_INACTIVE\020\002b\006proto3" 
};
+    descriptor = 
com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(descriptorData,
+        new com.google.protobuf.Descriptors.FileDescriptor[] {});
+    internal_static_org_apache_avro_protobuf_noopt_User_descriptor = 
getDescriptor().getMessageTypes().get(0);
+    internal_static_org_apache_avro_protobuf_noopt_User_fieldAccessorTable = 
new com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+        internal_static_org_apache_avro_protobuf_noopt_User_descriptor,
+        new java.lang.String[] { "Name", "Id", "Status", });
+    descriptor.resolveAllFeaturesImmutable();
+  }
+
+  // @@protoc_insertion_point(outer_class_scope)
+}
diff --git a/lang/java/protobuf/src/test/protobuf/test.proto 
b/lang/java/protobuf/src/test/protobuf/test.proto
index 12fa5635a7..80d800ffc1 100644
--- a/lang/java/protobuf/src/test/protobuf/test.proto
+++ b/lang/java/protobuf/src/test/protobuf/test.proto
@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+syntax = "proto2";
+
 package org.apache.avro.protobuf.noopt;
 
 import "google/protobuf/timestamp.proto";
diff --git a/lang/java/protobuf/src/test/protobuf/test_proto3.proto 
b/lang/java/protobuf/src/test/protobuf/test_proto3.proto
new file mode 100644
index 0000000000..8244ed77ac
--- /dev/null
+++ b/lang/java/protobuf/src/test/protobuf/test_proto3.proto
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto3";
+
+package org.apache.avro.protobuf.noopt;
+
+enum Status {
+  STATUS_UNKNOWN = 0;
+  STATUS_ACTIVE = 1;
+  STATUS_INACTIVE = 2;
+}
+
+message User {
+  string name = 1;
+  int32 id = 2;
+  Status status = 3;
+}
diff --git a/pom.xml b/pom.xml
index 9dac476883..b7bb1a8a2a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -480,6 +480,7 @@
                 
<exclude>lang/java/mapred/src/test/resources/org/apache/avro/mapreduce/mapreduce-test-input.txt</exclude>
                 
<exclude>lang/java/mapred/src/test/resources/org/apache/avro/mapreduce/mapreduce-test-input.avro/*</exclude>
                 
<exclude>lang/java/protobuf/src/test/java/org/apache/avro/protobuf/noopt/Test.java</exclude>
+                
<exclude>lang/java/protobuf/src/test/java/org/apache/avro/protobuf/noopt/TestProto3.java</exclude>
                 
<exclude>lang/java/protobuf/src/test/java/org/apache/avro/protobuf/multiplefiles/A.java</exclude>
                 
<exclude>lang/java/protobuf/src/test/java/org/apache/avro/protobuf/multiplefiles/Foo.java</exclude>
                 
<exclude>lang/java/protobuf/src/test/java/org/apache/avro/protobuf/multiplefiles/FooOrBuilder.java</exclude>


Reply via email to