There are 3 updates, 1 comment.
 
 
XWiki Platform / cid:jira-generated-image-avatar-be1afc10-9451-450d-88e2-ad44f32c2d64 XWIKI-22036 Open

Call "hasNext" before call "next" in XWikiDocumentArchive

 
View issue   ยท   Add comment
 

3 updates

 
cid:jira-generated-image-avatar-6dbcaed7-9851-45b4-a005-a2faa1cc45ef Changes by Vincent Massol on 14/Nov/24 10:43
 
Description: If it cannot be guaranteed that the Iterator will successfully access the next element using the "next" method, it is necessary to use the "hasNext" method to check before attempting to access the next element. 

1. 

If the number of nodes is an odd number, the second "it.next()" may cause NoSuchElementExceptions.
{
quote code }// xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java
public void setArchive(String text) throws XWikiException {
...
Collection nodes = archive.getNodes(getWikiReference(), getId());
for (Iterator it = nodes.iterator(); it.hasNext();) {
XWikiRCSNodeInfo nodeInfo = (XWikiRCSNodeInfo) it.next();
XWikiRCSNodeContent nodeContent = (XWikiRCSNodeContent) it.next();
updateNode(nodeInfo);
this.updatedNodeInfos.add(nodeInfo);


{
quote code }
2. 

I couldn't find any logic that ensures the 'tables' variable is not empty. If there is no such logic in place, it is recommended to add proper validation to ensure that 'tables' is not empty before accessing it.

 
{
quote code }// xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/internal/store/hibernate/query/HqlQueryUtils.java
private static String getTableName(Table table, Map<String, String> tables)
{
String tableName = tables.values().iterator().next();


{
quote code }
Assignee: Vincent Massol
Pull Request Status: Awaiting Committer feedback
 
 

1 comment

 
cid:jira-generated-image-avatar-6dbcaed7-9851-45b4-a005-a2faa1cc45ef Vincent Massol on 14/Nov/24 10:45
 

A pull request was opened at https://github.com/xwiki/xwiki-platform/pull/3036