- Map<Integer, Comment> lastOfLevel =
- new HashMap<Integer, Comment>();
-
- for (Comment c : story.getComments()) {
- int level = Integer.parseInt(c.getId());
- lastOfLevel.put(level, c);
- if (level <= 1) {
- comments.add(c);
- } else {
- Comment parent = lastOfLevel.get(level - 1);
- if (parent != null ){
- parent.add(c);
- } else {
- // bad data
+ Map<Integer, Comment> lastOfLevel = new HashMap<Integer, Comment>();
+
+ if (!story.getComments().isEmpty()) {
+ // comments are saved under a main ID (which is a copy of comment 1)
+ // TODO: fix the cause instead of working around it here
+ for (Comment c : story.getComments().get(0)) {
+ int level = Integer.parseInt(c.getId());
+ lastOfLevel.put(level, c);
+ if (level <= 1) {