Bug 65715 - An inexplicable ‘break’ statement in XSSFSheet
Summary: An inexplicable ‘break’ statement in XSSFSheet
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-01 07:34 UTC by chaos
Modified: 2021-12-01 11:20 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description chaos 2021-12-01 07:34:32 UTC
public XSSFDrawing getDrawingPatriarch() {
        CTDrawing ctDrawing = getCTDrawing();
        if (ctDrawing != null) {
            // Search the referenced drawing in the list of the sheet's relations
            for (RelationPart rp : getRelationParts()){
                POIXMLDocumentPart p = rp.getDocumentPart();
                if (p instanceof XSSFDrawing) {
                    XSSFDrawing dr = (XSSFDrawing)p;
                    String drId = rp.getRelationship().getId();
                    if (drId.equals(ctDrawing.getId())){
                        return dr;
                    }
                    break;
                }
            }
            LOG.atError().log("Can't find drawing with id={} in the list of the sheet's relationships", ctDrawing.getId());
        }
        return null;
    }

I don‘t know why there is a ’break‘ statement.It makes the loop meaningless.Actually,the 'if' in front means there may be multiple drawing in one sheet.So i think this maybe a bug.
Comment 1 PJ Fanning 2021-12-01 08:50:22 UTC
Thanks - does look strange. I've modified it with r1895446
Comment 2 PJ Fanning 2021-12-01 08:51:28 UTC
should be r1895447
Comment 3 PJ Fanning 2021-12-01 11:20:14 UTC
I ran a test in jdoodle and break does leave the for loop early.

```
import java.util.*;

public class MyClass {
    public static void main(String args[]) {
        ArrayList<String> strs = new ArrayList<>();
        strs.add("aon");
        strs.add("dó");
        strs.add("trí");
        for(String str : strs) {
            System.out.println(str);
            break;
        }
    }
}
```

In this case, only `aon` gets printed.