[ 
https://issues.apache.org/jira/browse/DOXIA-662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17563844#comment-17563844
 ] 

ASF GitHub Bot commented on DOXIA-662:
--------------------------------------

michael-o commented on code in PR #106:
URL: https://github.com/apache/maven-doxia/pull/106#discussion_r916030633


##########
doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java:
##########
@@ -69,6 +72,10 @@
     /** The stack. */
     private final Stack<IndexEntry> stack;
 
+    /** A map containing all used ids of index entries as key and how often 
they are used as value
+     * (0-based, i.e. 0 means used 1 time). */
+    private final Map<String, AtomicInteger> usedIds;

Review Comment:
   Why atomic? All you need is a mutuable integer, no? This component is 
neither singleton not in MT use.



##########
doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java:
##########
@@ -323,6 +331,26 @@ public void text( String text )
         }
     }
 
+    /**
+     * Converts the given id into a unique one by potentially suffix it with a 
counter value.
+     * @param id
+     * @return the unique id
+     */
+    String getUniqueId( String id )
+    {
+        final String uniqueId;
+        if ( usedIds.containsKey( id ) )
+        {
+            uniqueId = id + "_" + usedIds.get( id ).incrementAndGet();
+        }
+        else
+        {
+            usedIds.put( id, new AtomicInteger() );

Review Comment:
   What about `computeIfAbsent()`?





> Non unique IDs generated by IndexingSink
> ----------------------------------------
>
>                 Key: DOXIA-662
>                 URL: https://issues.apache.org/jira/browse/DOXIA-662
>             Project: Maven Doxia
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.0.0-M3
>            Reporter: Konrad Windszus
>            Priority: Major
>
> If a HTML source contains non-unique headlines (i.e. two or more headlines 
> with the same text) in a single HTML page the IDs being generated out of 
> those are not unique.
> That leads to issues with e.g. the TOC macro 
> (https://github.com/apache/maven-doxia/blob/2aea4500ba6559b91fe3a4b83a5d3aafc10116b4/doxia-core/src/main/java/org/apache/maven/doxia/macro/toc/TocMacro.java#L155)
>  which writes an anchor link leveraging that id.
> The problematic line is 
> https://github.com/apache/maven-doxia/blob/2aea4500ba6559b91fe3a4b83a5d3aafc10116b4/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java#L314
>  which just uses the (sanitized) title as id. In case of conflicts the title 
> needs to be suffixed with an index to be unique.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to