]> source.dussan.org Git - gitblit.git/commitdiff
fix NullPointerException in ITicketService and add TestCase 170/head
authorKevin Walter <kevin.walter.private@googlemail.com>
Tue, 15 Apr 2014 00:00:42 +0000 (02:00 +0200)
committerKevin Walter <kevin.walter.private@googlemail.com>
Tue, 15 Apr 2014 00:07:02 +0000 (02:07 +0200)
src/main/java/com/gitblit/tickets/ITicketService.java
src/test/java/com/gitblit/tests/TicketServiceTest.java

index 9522e420ec00241ea1160cc790774c74618fab3a..7d6997572f16f21aa875fa88cf3b4952fa34449d 100644 (file)
@@ -713,27 +713,30 @@ public abstract class ITicketService {
        public final TicketModel getTicket(RepositoryModel repository, long ticketId) {
                TicketKey key = new TicketKey(repository, ticketId);
                TicketModel ticket = ticketsCache.getIfPresent(key);
-
+               
+               // if ticket not cached
                if (ticket == null) {
-                       // load & cache ticket
+                       //load ticket
                        ticket = getTicketImpl(repository, ticketId);
-                       if (ticket.hasPatchsets()) {
-                               Repository r = repositoryManager.getRepository(repository.name);
-                               try {
-                                       Patchset patchset = ticket.getCurrentPatchset();
-                                       DiffStat diffStat = DiffUtils.getDiffStat(r, patchset.base, patchset.tip);
-                                       // diffstat could be null if we have ticket data without the
-                                       // commit objects.  e.g. ticket replication without repo
-                                       // mirroring
-                                       if (diffStat != null) {
-                                               ticket.insertions = diffStat.getInsertions();
-                                               ticket.deletions = diffStat.getDeletions();
+                       // if ticket exists
+                       if (ticket != null) {
+                               if (ticket.hasPatchsets()) {
+                                       Repository r = repositoryManager.getRepository(repository.name);
+                                       try {
+                                               Patchset patchset = ticket.getCurrentPatchset();
+                                               DiffStat diffStat = DiffUtils.getDiffStat(r, patchset.base, patchset.tip);
+                                               // diffstat could be null if we have ticket data without the
+                                               // commit objects.  e.g. ticket replication without repo
+                                               // mirroring
+                                               if (diffStat != null) {
+                                                       ticket.insertions = diffStat.getInsertions();
+                                                       ticket.deletions = diffStat.getDeletions();
+                                               }
+                                       } finally {
+                                               r.close();
                                        }
-                               } finally {
-                                       r.close();
                                }
-                       }
-                       if (ticket != null) {
+                               //cache ticket
                                ticketsCache.put(key, ticket);
                        }
                }
index 5f94a46e08ffb86a869c21afc3e6b890b3de13d7..d91ce53397c291cd70d7c7e8e728b5fd35498657 100644 (file)
@@ -92,6 +92,10 @@ public abstract class TicketServiceTest extends GitblitUnitTest {
 \r
        @Test\r
        public void testLifecycle() throws Exception {\r
+               // query non-existent ticket\r
+               TicketModel nonExistent = service.getTicket(getRepository(), 0);\r
+               assertNull(nonExistent);\r
+               \r
                // create and insert a ticket\r
                Change c1 = newChange("testCreation() " + Long.toHexString(System.currentTimeMillis()));\r
                TicketModel ticket = service.createTicket(getRepository(), c1);\r