Prevent Guava InvalidCacheLoadException

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      The issueCache in hudson.plugins.jira.JiraSite make use of Guava cache.

      /**
       * Returns the remote issue with the given id or <code>null</code> if it wasn't found.
       */
      @CheckForNull
      public JiraIssue getIssue(final String id) throws IOException {
          try {
      
              Issue issue = issueCache.get(id, new Callable<Issue>() {
                  public Issue call() throws Exception {
                      JiraSession session = getSession();
                      Issue issue = null;
                      if (session != null) {
                          issue = session.getIssue(id);
                      }
                      return issue;
                  }
              });
      
              if (issue == null) {
                  return null;
              }
      
              return new JiraIssue(issue);
          } catch (ExecutionException e) {
              throw new IOException(e);
          }
      }
      

      As noticed in the com.google.common.cache.Cache JavaDoc,

      V get(K key, Callable<? extends V> valueLoader) throws ExecutionException;
      

      valueLoader must not return null; it may either return a non-null value or throw an exception.

      session.getIssue(id) may return null if no such issue exists, causing throwing unhandled RuntimeExcepting com.google.common.cache.CacheLoader$InvalidCacheLoadException.

      Since no such issue can be found in Jira site, we can positively cache the null issue.

      There are various reasons for the issue can NOT be found in Jira site. Let's leave it from this issue.

            Assignee:
            Zhenlei Huang
            Reporter:
            Zhenlei Huang
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: