You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2020/03/16 14:33:28 UTC

[juneau] branch master updated: JUNEAU-203

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

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f8fe3b  JUNEAU-203
9f8fe3b is described below

commit 9f8fe3ba27f577e428a1b020f68f8ff7cd453f41
Author: JamesBognar <ja...@apache.org>
AuthorDate: Mon Mar 16 10:33:10 2020 -0400

    JUNEAU-203
    
    Bean copy constructor can be confused with builder constructor.
---
 .../a/rttests/RoundTripTransformBeansTest.java     | 31 ++++++++++++++++++++++
 .../java/org/apache/juneau/reflect/ClassInfo.java  |  2 +-
 juneau-doc/docs/ReleaseNotes/8.1.4.html            |  3 +++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java
index ec1cd9f..0a2c9e2 100755
--- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java
+++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTransformBeansTest.java
@@ -641,4 +641,35 @@ public class RoundTripTransformBeansTest extends RoundTripTest {
 		x = roundTrip(x, F2.class);
 	}
 
+	//==================================================================================================================
+	// testBeanWithIncompleteCopyConstructor
+	//==================================================================================================================
+
+	public static class F {
+		public int f1, f2;
+
+		public F() {}
+
+		public F(F c) {
+			this.f1 = c.f1;
+		}
+
+		public static F create() {
+			F f = new F();
+			f.f1 = 1;
+			f.f2 = 2;
+			return f;
+		}
+	}
+
+	/**
+	 * The create() method and copy constructor should not be confused as the classes Builder class.
+	 */
+	@Test
+	public void testBeanWithIncompleteCopyConstructor() throws Exception {
+		F f = F.create();
+		f = roundTrip(f);
+		assertObjectEquals("{f1:1,f2:2}", f);
+	}
+
 }
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
index 7b03f78..d63aa1f 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/reflect/ClassInfo.java
@@ -602,7 +602,7 @@ public final class ClassInfo {
 	 */
 	public MethodInfo getBuilderCreateMethod() {
 		for (MethodInfo m : getDeclaredMethods())
-			if (m.isAll(PUBLIC, STATIC) && m.hasName("create") && (!m.hasReturnType(void.class)))
+			if (m.isAll(PUBLIC, STATIC) && m.hasName("create") && (!m.hasReturnType(void.class)) && (!m.hasReturnType(c)))
 				return m;
 		return null;
 	}
diff --git a/juneau-doc/docs/ReleaseNotes/8.1.4.html b/juneau-doc/docs/ReleaseNotes/8.1.4.html
index df120ac..86feb85 100644
--- a/juneau-doc/docs/ReleaseNotes/8.1.4.html
+++ b/juneau-doc/docs/ReleaseNotes/8.1.4.html
@@ -148,6 +148,9 @@
 			<li>Collections of beans with <c><ja>@Bean</ja>(bpi)</c> were not being serialized in the correct column order.			
 		</ul>
 	<li>
+		Fixed a bug where a copy constructor can erroneously be recognised as a builder constructor if the class also
+		has a static <c>create</c> method.  Net effect was that the copy constructor would needlessly be called during parsing.
+	<li>
 		HTML-Schema support is being deprecated due to low-use and difficulty in maintaining.  It will be removed in 9.0.
 </ul>