[JENKINS-32925] Add tracking to prevent stack overflows #351
Conversation
This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation. |
Oooo, nicely done. 🐝 |
@@ -147,6 +148,10 @@ | |||
public static Schema schemaFor(Class<?> clazz) { | |||
return new Schema(clazz); | |||
} | |||
|
|||
public static Schema schemaFor(Class<?> clazz, Stack<String> tracker) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐛 should be private
Good enough for the short term: addresses the stack overflow by simply omitting a legitimate choice. Later, if needed, we can introduce a new parameter type like |
BTW there is an open issue for this on issues.jenkins-ci.org, assigned to you IIRC; link to it please. |
this.type = clazz; | ||
if(tracker == null){ | ||
tracker = new Stack<String>(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or more simply, pass new Stack<String>()
as the argument in line 166.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the @Nonnull
annotation to the Stack in the constructor. I really like that annotation.
Thanks for the reviews. I wanted to make a fairly minimal change so there wouldn't be that huge disruption to all the content generators. I definitely will keep introducing the error type in the back of my mind if this ends up being needed down the road. |
🐝 |
While studying this fix, I noticed that this change missed the use of The recursive portion of the stack is as follows (as of c85a422):
|
Probably better to leave a comment in jenkinsci/structs-plugin#1 requesting a test case be added that has something like |
JENKINS-32925
To prevent stack overflows, especially in the Multiple SCMs case, track the subtypes to make sure the type isn't trying to discover itself. When that case is detected, don't log, and return back up the stack. This will only prevent duplication vertically, not horizontally.
@reviewbybees esp @jglick & @abayer