jenkinsci/jenkins · error · IllegalArgumentException
No ancestor of type {} in the request
Error message
No ancestor of type {} in the request What it means
Thrown by Util.getNearestAncestorOfTypeOrThrow when the StaplerRequest's findAncestorObject(clazz) returns null — meaning the current request URL path does not traverse through any object of the requested type. This utility enforces that a required ancestor object (e.g., a Job, View, or Jenkins instance) is present in the URL hierarchy.
Source
Thrown at core/src/main/java/hudson/Util.java:1910
* @return positive number of days between the given date and now
* @see #daysBetween(Date, Date)
*/
@Restricted(NoExternalUse.class)
public static long daysElapsedSince(@NonNull Date date) {
return Math.max(0, daysBetween(date, new Date()));
}
/**
* Find the specific ancestor, or throw an exception.
* Useful for an ancestor we know is inside the URL to ease readability
*
* @since 2.475
*/
@Restricted(NoExternalUse.class)
public static @NonNull <T> T getNearestAncestorOfTypeOrThrow(@NonNull StaplerRequest2 request, @NonNull Class<T> clazz) {
T t = request.findAncestorObject(clazz);
if (t == null) {
throw new IllegalArgumentException("No ancestor of type " + clazz.getName() + " in the request");
}
return t;
}
/**
* @deprecated use {@link #getNearestAncestorOfTypeOrThrow(StaplerRequest2, Class)}
*/
@Deprecated
@Restricted(NoExternalUse.class)
public static @NonNull <T> T getNearestAncestorOfTypeOrThrow(@NonNull StaplerRequest request, @NonNull Class<T> clazz) {
return getNearestAncestorOfTypeOrThrow(StaplerRequest.toStaplerRequest2(request), clazz);
}
@Restricted(NoExternalUse.class)
public static void printRedirect(String contextPath, String redirectUrl, String message, PrintWriter out) {
out.printf(
"<html><head>" +
"<meta http-equiv='refresh' content='1;url=%1$s'/>" +View on GitHub (pinned to 2e228ff40b)
Solutions
- Ensure the URL path that triggers this code includes the expected ancestor object (e.g., access the view via /job/<jobname>/... rather than a top-level path).
- If the ancestor may legitimately be absent, use request.findAncestorObject(clazz) directly and handle the null case instead of the throwing variant.
- Verify Stapler URL bindings and StaplerRequest routing to ensure the expected object is in the ancestor chain.
Example fix
// before
Job job = Util.getNearestAncestorOfTypeOrThrow(request, Job.class);
// after
Job job = request.findAncestorObject(Job.class);
if (job == null) {
// handle missing ancestor gracefully (redirect, error page, etc.)
return;
} Defensive patterns
Strategy: type-guard
Validate before calling
// Check ancestor presence before calling
T ancestor = request.findAncestorObject(clazz);
if (ancestor == null) {
// handle: redirect, show error, or use default
throw new CmdLineException("This action requires a " + clazz.getSimpleName() + " in the URL path.");
} Type guard
public static <T> boolean hasAncestorOfType(StaplerRequest2 req, Class<T> clazz) {
return req.findAncestorObject(clazz) != null;
} Try / catch
try {
T ancestor = Util.getNearestAncestorOfTypeOrThrow(request, clazz);
} catch (IllegalArgumentException e) {
// No ancestor of type T in the URL — return 404 or redirect
res.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
} Prevention
- Ensure Stapler URL bindings route through the expected ancestor object path.
- Use the non-throwing variant (findAncestorObject) when absence is a valid condition.
- Test endpoints from multiple URL entry points to verify ancestor presence.
When it happens
Trigger: The Stapler request URL does not contain a path segment that maps to an object of type T. For example, calling getNearestAncestorOfTypeOrThrow(request, Job.class) from a URL like /jenkins/configure that does not traverse a Job object.
Common situations: A Stapler-bound URL handler or jelly view calls this utility expecting a parent object that is only present on specific URL paths (e.g., /job/<name>/...); the endpoint is accessed from a different URL context where the ancestor is absent; a plugin routes to a view from a non-standard path that skips the expected parent.
Related errors
- A logger named "{0}" does not exist. Add a logger by this na
- The name “{0}” is already in use.
- Null value not allowed as an environment variable: ${key}
- invalid iconSize
- Ambiguous plugin: {0}
AI-assisted analysis of jenkinsci/jenkins@2e228ff40b (2026-08-14).
Data as JSON: /api/errors/9239bd9fc3fecd2d.
Report an issue: GitHub.