EnvInject throws a StringIndexOutOfBoundsException in BuildCauseRetriever.getTriggeredCause if the class that triggered it was anonymous. This is because getTriggerName uses cause.getClass().getSimpleName(), which returns an empty string for anonymous classes, empty strings are skipped when getTriggeredCause iterates over build causes, but it always assumes that there is at least one non-empty build cause.
To reproduce, create a trigger that uses an anonymous Cause like this:
To work around this, the above snippet can be rewritten to avoid the anonymous class:
I'm not sure which fix would be most consistent with the intent of the ENV_CAUSE variable for custom triggers. I see these options:
- Skip setting an ENV_CAUSE, possibly log a warning
- Use the parent class as the trigger name
- make the trigger "ANONYMOUSTRIGGER", possibly prefixed by the parent class