@@ -88,6 +88,9 @@ private boolean matches(final Node<T> current, final NameIterator ni) {
8888 return false ;
8989 }
9090
91+ // Sentinel to distinguish "matched with null value" from "no match" in the recursive get traversal
92+ private static final Object NO_MATCH = new Object ();
93+
9194 /**
9295 * Returns the value matching a name with any of the names contained in this matcher.
9396 *
@@ -100,21 +103,26 @@ public T get(final String name) {
100103 return result ;
101104 }
102105
106+ if (properties .containsKey (name )) {
107+ return null ;
108+ }
109+
103110 NameIterator ni = new NameIterator (name );
104- return get (wildcards , ni );
111+ result = get (wildcards , ni );
112+ return result == noMatch () ? null : result ;
105113 }
106114
107115 private T get (final Node <T > current , final NameIterator ni ) {
108116 if (!ni .hasNext ()) {
109- return current .terminal ? current .value : null ;
117+ return current .terminal ? current .value : noMatch () ;
110118 }
111119
112120 int position = ni .getPosition ();
113121 Node <T > child = current .find (ni );
114122 if (child != null ) {
115123 ni .next ();
116124 T result = get (child , ni );
117- if (result != null ) {
125+ if (result != noMatch () ) {
118126 return result ;
119127 }
120128 }
@@ -127,7 +135,7 @@ private T get(final Node<T> current, final NameIterator ni) {
127135 ni .setPosition (position );
128136 ni .next ();
129137 T result = get (current .wildcard , ni );
130- if (result != null ) {
138+ if (result != noMatch () ) {
131139 return result ;
132140 }
133141 if (current .wildcard .terminal && !current .greedy ) {
@@ -139,7 +147,7 @@ private T get(final Node<T> current, final NameIterator ni) {
139147 return current .value ;
140148 }
141149
142- return null ;
150+ return noMatch () ;
143151 }
144152
145153 protected void add (final String name ) {
@@ -209,6 +217,11 @@ protected void put(final String name, final T value) {
209217 }
210218 }
211219
220+ @ SuppressWarnings ("unchecked" )
221+ private static <T > T noMatch () {
222+ return (T ) NO_MATCH ;
223+ }
224+
212225 public static final class Node <T > {
213226 String path ;
214227 T value ;
0 commit comments