Skip to content

Commit

Permalink
Tolerate HttpResponse thrown from Descriptor.newInstance (#9495)
Browse files Browse the repository at this point in the history
* Tolerate `HttpResponse` thrown from `Descriptor.newInstance`

* Incremental version

* Pick up release of jenkinsci/stapler#571
  • Loading branch information
jglick authored Jul 28, 2024
1 parent 11f87f7 commit cbfe2d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ THE SOFTWARE.
<properties>
<commons-fileupload2.version>2.0.0-M2</commons-fileupload2.version>
<slf4jVersion>2.0.13</slf4jVersion>
<stapler.version>1881.vd39f3ee5c629</stapler.version>
<stapler.version>1892.v73465f3d074d</stapler.version>
<groovy.version>2.4.21</groovy.version>
</properties>

Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/hudson/model/Descriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@ public T newInstance(@Nullable StaplerRequest req, @NonNull JSONObject formData)
return verifyNewInstance(bindJSON(req, clazz, formData, true));
}
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | RuntimeException e) {
if (e instanceof RuntimeException && e instanceof HttpResponse) {
throw (RuntimeException) e;
}
throw new LinkageError("Failed to instantiate " + clazz + " from " + RedactSecretJsonInErrorMessageSanitizer.INSTANCE.sanitize(formData), e);
}
}
Expand Down Expand Up @@ -674,7 +677,7 @@ public Object instantiate(Class actualType, JSONObject json) {
+ actualType.getName() + " " + json);
}
} catch (Exception x) {
LOGGER.log(Level.WARNING, "falling back to default instantiation " + actualType.getName() + " " + json, x);
LOGGER.log(x instanceof HttpResponse ? Level.FINE : Level.WARNING, "falling back to default instantiation " + actualType.getName() + " " + json, x);
// If nested objects are not using newInstance, bindJSON will wind up throwing the same exception anyway,
// so logging above will result in a duplicated stack trace.
// However if they *are* then this is the only way to find errors in that newInstance.
Expand Down

0 comments on commit cbfe2d4

Please sign in to comment.