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 2021/02/11 22:51:33 UTC

[tapestry-5] 01/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 5.6.x
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git

commit 6dcc25e533cd79b9d0bfc91b8002de488d6baf89
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
    # Conflicts:
    #	commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java
---
 .../tapestry5/ioc/internal/services/TypeCoercerImpl.java      | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java b/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java
index c93655d..68927c4 100644
--- a/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java
+++ b/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java
@@ -280,6 +280,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