Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

AVRO-1630. Java: Creating Builder from instance loses data. Contribut…

…ed by Niels Basjes.

git-svn-id: https://svn.apache.org/repos/asf/avro/trunk@1656749 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 6a80468a68de9bd035d5cc21d2ee664e1956c884 1 parent a471a72
Thomas White authored
3  CHANGES.txt
View
@@ -119,6 +119,9 @@ Trunk (not yet released)
AVRO-1624. Java. Surefire forkMode is deprecated. (Niels Basjes via
tomwhite)
+ AVRO-1630. Java: Creating Builder from instance loses data. (Niels Basjes
+ via tomwhite)
+
Avro 1.7.7 (23 July 2014)
NEW FEATURES
6 lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
View
@@ -260,7 +260,11 @@ public class ${this.mangle($schema.getName())}#if ($schema.isError()) extends or
*/
public ${this.javaType($field.schema())}.Builder ${this.generateGetBuilderMethod($schema, $field)}() {
if (${this.mangle($field.name(), $schema.isError())}Builder == null) {
- ${this.generateSetBuilderMethod($schema, $field)}(${this.javaType($field.schema())}.newBuilder());
+ if (${this.generateHasMethod($schema, $field)}()) {
+ ${this.generateSetBuilderMethod($schema, $field)}(${this.javaType($field.schema())}.newBuilder(${this.mangle($field.name(), $schema.isError())}));
+ } else {
+ ${this.generateSetBuilderMethod($schema, $field)}(${this.javaType($field.schema())}.newBuilder());
+ }
}
return ${this.mangle($field.name(), $schema.isError())}Builder;
}
52 lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java
View
@@ -116,6 +116,58 @@ public void copyBuilder() {
assertEquals("Bar", request2.getHttpRequest().getURI().getParameters().get(0).getValue());
}
+ @Test
+ public void createBuilderFromInstance(){
+ Request.Builder requestBuilder1 = createPartialBuilder();
+ requestBuilder1
+ .getConnectionBuilder()
+ .setNetworkAddress("1.1.1.1");
+
+ Request request1 = requestBuilder1.build();
+
+ Request.Builder requestBuilder2 = Request.newBuilder(request1);
+
+ requestBuilder2
+ .getConnectionBuilder()
+ .setNetworkAddress("2.2.2.2");
+
+ requestBuilder2
+ .getHttpRequestBuilder()
+ .getUserAgentBuilder()
+ .setId("Bar");
+
+ requestBuilder2
+ .getHttpRequestBuilder()
+ .getURIBuilder()
+ .setMethod(HttpMethod.POST);
+
+ requestBuilder2
+ .getHttpRequestBuilder()
+ .getUserAgentBuilder()
+ .setUseragent("Firefox 456");
+
+ Request request2 = requestBuilder2.build();
+
+ assertEquals(NetworkType.IPv4, request1.getConnection().getNetworkType());
+ assertEquals("1.1.1.1", request1.getConnection().getNetworkAddress());
+ assertEquals("Chrome 123", request1.getHttpRequest().getUserAgent().getUseragent());
+ assertEquals("Foo", request1.getHttpRequest().getUserAgent().getId());
+ assertEquals(HttpMethod.GET, request1.getHttpRequest().getURI().getMethod());
+ assertEquals("/index.html", request1.getHttpRequest().getURI().getPath());
+ assertEquals(1, request1.getHttpRequest().getURI().getParameters().size());
+ assertEquals("Foo", request1.getHttpRequest().getURI().getParameters().get(0).getName());
+ assertEquals("Bar", request1.getHttpRequest().getURI().getParameters().get(0).getValue());
+
+ assertEquals(NetworkType.IPv4, request2.getConnection().getNetworkType());
+ assertEquals("2.2.2.2", request2.getConnection().getNetworkAddress());
+ assertEquals("Firefox 456", request2.getHttpRequest().getUserAgent().getUseragent());
+ assertEquals("Bar", request2.getHttpRequest().getUserAgent().getId());
+ assertEquals(HttpMethod.POST, request2.getHttpRequest().getURI().getMethod());
+ assertEquals("/index.html", request2.getHttpRequest().getURI().getPath());
+ assertEquals(1, request2.getHttpRequest().getURI().getParameters().size());
+ assertEquals("Foo", request2.getHttpRequest().getURI().getParameters().get(0).getName());
+ assertEquals("Bar", request2.getHttpRequest().getURI().getParameters().get(0).getValue());
+ }
private Request.Builder createLastOneTestsBuilder() {
Request.Builder requestBuilder = Request.newBuilder();
Please sign in to comment.
Something went wrong with that request. Please try again.