Repository: wicket
Updated Branches:
  refs/heads/master 40fe9b98e -> 5a7a089d5


WICKET-6109 Enclosure - "IllegalArgumentException: Argument 'markup' may not be 
null" after app restart


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/5a7a089d
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/5a7a089d
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/5a7a089d

Branch: refs/heads/master
Commit: 5a7a089d57f022467cdea8b2fae531729a6dcb4d
Parents: 40fe9b9
Author: Andrea Del Bene <[email protected]>
Authored: Fri Mar 11 12:42:57 2016 +0100
Committer: Andrea Del Bene <[email protected]>
Committed: Fri Mar 11 21:36:43 2016 +0100

----------------------------------------------------------------------
 .../markup/parser/AbstractMarkupFilter.java     | 37 +++++++++++++++-----
 ...ithWicketMessagePage_invisible_expected.html |  2 +-
 ...eWithWicketMessagePage_visible_expected.html |  2 +-
 3 files changed, 31 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/5a7a089d/wicket-core/src/main/java/org/apache/wicket/markup/parser/AbstractMarkupFilter.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/markup/parser/AbstractMarkupFilter.java
 
b/wicket-core/src/main/java/org/apache/wicket/markup/parser/AbstractMarkupFilter.java
index db53a77..a29f774 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/markup/parser/AbstractMarkupFilter.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/markup/parser/AbstractMarkupFilter.java
@@ -17,6 +17,8 @@
 package org.apache.wicket.markup.parser;
 
 import java.text.ParseException;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.wicket.MetaDataKey;
@@ -44,8 +46,13 @@ public abstract class AbstractMarkupFilter implements 
IMarkupFilter
        /** The next MarkupFilter in the chain */
        private IMarkupFilter parent;
 
-       /** A key for a request-relative counter (see {@link 
#getRequestUniqueId()}) **/
-       private final static MetaDataKey<AtomicInteger> REQUEST_COUNTER_KEY = 
new MetaDataKey<AtomicInteger>()
+       /**
+        *  A key for a request-relative map of counters.
+        *  As map keys we use the {@link 
org.apache.wicket.markup.MarkupResourceStream} cacheKey, 
+        *  meaning that each {@link 
org.apache.wicket.markup.MarkupResourceStream} has its own counter. 
+        *  The counters are used by {@link #getRequestUniqueId()} to get 
unique ids for markup tags.
+        * **/
+       private final static MetaDataKey<Map<String, AtomicInteger>> 
REQUEST_COUNTER_KEY = new MetaDataKey<Map<String, AtomicInteger>>()
        {
                private static final long serialVersionUID = 1L;
        };
@@ -196,8 +203,9 @@ public abstract class AbstractMarkupFilter implements 
IMarkupFilter
        }
 
        /**
-        * Returns an id using a request-relative counter. This can be
-        * useful for autocomponent tags that need to get a tag id.
+        * Returns an id using the request-relative counter associated with the 
+        * underlying {@link org.apache.wicket.markup.MarkupResourceStream}. 
+        * This can be useful for autocomponent tags that need to get a tag id.
         * 
         * @return
         *              the request-relative id
@@ -205,15 +213,28 @@ public abstract class AbstractMarkupFilter implements 
IMarkupFilter
        protected int getRequestUniqueId()
        {
                RequestCycle requestCycle = RequestCycle.get();
-               AtomicInteger counter = 
requestCycle.getMetaData(REQUEST_COUNTER_KEY);
+               Map<String, AtomicInteger> markupUniqueCounters = 
requestCycle.getMetaData(REQUEST_COUNTER_KEY);
+               String cacheKey = getMarkupResourceStream().getCacheKey();
+               
+               if (markupUniqueCounters == null)
+               {
+                       markupUniqueCounters = new HashMap<>();
+                       
+                       requestCycle.setMetaData(REQUEST_COUNTER_KEY, 
markupUniqueCounters);
+               }
+               
+               AtomicInteger counter = markupUniqueCounters.get(cacheKey);
                
                if (counter == null)
                {
                        counter = new AtomicInteger();
-                       
-                       requestCycle.setMetaData(REQUEST_COUNTER_KEY, counter);
+                       markupUniqueCounters.put(cacheKey, counter);
                }
                
-               return counter.getAndIncrement();
+           int cacheHash = cacheKey == null ? 0 : cacheKey.hashCode();
+               
+           //add the counter value to the string hash 
+           //using the same algorithm of String#hashCode() 
+           return  cacheHash * 31 + counter.getAndIncrement();
        }
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/5a7a089d/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_invisible_expected.html
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_invisible_expected.html
 
b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_invisible_expected.html
index ea1d13e..267e77b 100644
--- 
a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_invisible_expected.html
+++ 
b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_invisible_expected.html
@@ -21,6 +21,6 @@
        <title>Wicket 4520</title>
 </head>
 <body>
-       <div id="wicket__message__attr__01" style="display:none"></div>
+       <div id="wicket__message__attr__11346339991" style="display:none"></div>
 </body>
 </html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/wicket/blob/5a7a089d/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_visible_expected.html
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_visible_expected.html
 
b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_visible_expected.html
index c61bd39..2ebffb1 100644
--- 
a/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_visible_expected.html
+++ 
b/wicket-core/src/test/java/org/apache/wicket/markup/html/internal/InlineEnclosureWithWicketMessagePage_visible_expected.html
@@ -21,7 +21,7 @@
        <title>Wicket 4520</title>
 </head>
 <body>
-       <div id="wicket__message__attr__01" title="Some title">
+       <div id="wicket__message__attr__11346339991" title="Some title">
                <div>Inner div
                        <span>A Label</span>
                </div>

Reply via email to