]> source.dussan.org Git - gitblit.git/commitdiff
Fix NPEs when handling referenced milestones that do not exist 52/152/1
authorJames Moger <james.moger@gitblit.com>
Thu, 4 Sep 2014 18:59:05 +0000 (14:59 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 4 Sep 2014 18:59:05 +0000 (14:59 -0400)
src/main/java/com/gitblit/tickets/ITicketService.java
src/main/java/com/gitblit/wicket/pages/TicketPage.java

index 668d0bcc11047fa79c3354735b6bb399a0980f81..4cf099fffd4a1b0555e3d65be731ccd3f8635400 100644 (file)
@@ -670,21 +670,24 @@ public abstract class ITicketService {
                Repository db = null;
                try {
                        db = repositoryManager.getRepository(repository.name);
-                       TicketMilestone milestone = getMilestone(repository, oldName);
+                       TicketMilestone tm = getMilestone(repository, oldName);
+                       if (tm == null) {
+                               return false;
+                       }
                        StoredConfig config = db.getConfig();
                        config.unsetSection(MILESTONE, oldName);
-                       config.setString(MILESTONE, newName, STATUS, milestone.status.name());
-                       config.setString(MILESTONE, newName, COLOR, milestone.color);
-                       if (milestone.due != null) {
+                       config.setString(MILESTONE, newName, STATUS, tm.status.name());
+                       config.setString(MILESTONE, newName, COLOR, tm.color);
+                       if (tm.due != null) {
                                config.setString(MILESTONE, newName, DUE,
-                                               new SimpleDateFormat(DUE_DATE_PATTERN).format(milestone.due));
+                                               new SimpleDateFormat(DUE_DATE_PATTERN).format(tm.due));
                        }
                        config.save();
 
                        milestonesCache.remove(repository.name);
 
                        TicketNotifier notifier = createNotifier();
-                       for (QueryResult qr : milestone.tickets) {
+                       for (QueryResult qr : tm.tickets) {
                                Change change = new Change(createdBy);
                                change.setField(Field.milestone, newName);
                                TicketModel ticket = updateTicket(repository, qr.number, change);
@@ -738,6 +741,9 @@ public abstract class ITicketService {
                Repository db = null;
                try {
                        TicketMilestone tm = getMilestone(repository, milestone);
+                       if (tm == null) {
+                               return false;
+                       }
                        db = repositoryManager.getRepository(repository.name);
                        StoredConfig config = db.getConfig();
                        config.unsetSection(MILESTONE, milestone);
index f5f63d23027a7af7dcd32d7e1cd38df1686272d3..b1f94a5b3bd8681c5689a3f1c1f2669326d90b2c 100644 (file)
@@ -249,9 +249,12 @@ public class TicketPage extends RepositoryPage {
                        add(new Label("milestone"));\r
                } else {\r
                        // link to milestone query\r
-                       TicketMilestone milestone = app().tickets().getMilestone(repository, ticket.milestone);\r
+                       TicketMilestone tm = app().tickets().getMilestone(repository, ticket.milestone);\r
+                       if (tm == null) {\r
+                               tm = new TicketMilestone(ticket.milestone);\r
+                       }\r
                        PageParameters milestoneParameters;\r
-                       if (milestone.isOpen()) {\r
+                       if (tm.isOpen()) {\r
                                milestoneParameters = WicketUtils.newOpenTicketsParameter(repositoryName);\r
                        } else {\r
                                milestoneParameters = WicketUtils.newRepositoryParameter(repositoryName);\r
@@ -260,10 +263,10 @@ public class TicketPage extends RepositoryPage {
                        int progress = 0;\r
                        int open = 0;\r
                        int closed = 0;\r
-                       if (milestone != null) {\r
-                               progress = milestone.getProgress();\r
-                               open = milestone.getOpenTickets();\r
-                               closed = milestone.getClosedTickets();\r
+                       if (tm != null) {\r
+                               progress = tm.getProgress();\r
+                               open = tm.getOpenTickets();\r
+                               closed = tm.getClosedTickets();\r
                        }\r
 \r
                        Fragment milestoneProgress = new Fragment("milestone", "milestoneProgressFragment", this);\r