diff --git a/core/src/main/java/hudson/model/ViewGroupMixIn.java b/core/src/main/java/hudson/model/ViewGroupMixIn.java
index <HASH>..<HASH> 100644
--- a/core/src/main/java/hudson/model/ViewGroupMixIn.java
+++ b/core/src/main/java/hudson/model/ViewGroupMixIn.java
@@ -163,12 +163,14 @@ public abstract class ViewGroupMixIn {
     }
 
     /**
-     * Returns the primary {@link View} that renders the top-page of Hudson.
+     * Returns the primary {@link View} that renders the top-page of Hudson or
+     * {@code null} if there is no primary one defined.
      */
     @Exported
+    @CheckForNull
     public View getPrimaryView() {
         View v = getView(primaryView());
-        if(v==null) // fallback
+        if(v==null && !views().isEmpty()) // fallback
             v = views().get(0);
         return v;
     }
Merge pull request #<I> from pilou-/handle_empty_views

[JENKINS-<I>] getPrimaryView: return null if no view is defined

(cherry picked from commit 8bc<I>f<I>e<I>a1d<I>c<I>b7bc7dd<I>e5db1)