You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2020/12/06 13:51:23 UTC

[tapestry-5] 02/02: TAP5-2651: TypeCoercer favoring exact match coercions

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

thiagohp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git

commit b5b2e74bc0460a326efbb6814d7583078588fa11
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Sun Dec 6 10:50:59 2020 -0300

    TAP5-2651: TypeCoercer favoring exact match coercions
    
    over indirect/intermediate ones
---
 .../tapestry5/commons/internal/services/TypeCoercerImpl.java | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/commons/src/main/java/org/apache/tapestry5/commons/internal/services/TypeCoercerImpl.java b/commons/src/main/java/org/apache/tapestry5/commons/internal/services/TypeCoercerImpl.java
index 681fa17..b89eb64 100644
--- a/commons/src/main/java/org/apache/tapestry5/commons/internal/services/TypeCoercerImpl.java
+++ b/commons/src/main/java/org/apache/tapestry5/commons/internal/services/TypeCoercerImpl.java
@@ -17,6 +17,7 @@ import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.WeakHashMap;
 
@@ -286,6 +287,17 @@ public class TypeCoercerImpl extends LockSupport implements TypeCoercer
         {
             return searchForNullCoercion(targetType);
         }
+        
+        // Trying to find exact match.
+        Optional<CoercionTuple> maybeTuple = 
+                getTuples(sourceType, targetType).stream()
+                    .filter((t) -> sourceType.equals(t.getSourceType()) && 
+                            targetType.equals(t.getTargetType())).findFirst();
+        
+        if (maybeTuple.isPresent())
+        {
+            return maybeTuple.get().getCoercion();
+        }
 
         // These are instance variables because this method may be called concurrently.
         // On a true race, we may go to the work of seeking out and/or fabricating