Solve crashes with Addon#allLoaded call (#1959)

If some addon has code in Addon#allLoaded that crashes the call, then it did not disable addon as well as did not call allLoaded for every other addon that was left in the list.

This should be solved by adding an extra try-catch.
This commit is contained in:
BONNe 2022-04-01 00:12:27 +03:00 committed by GitHub
parent 9f21314818
commit 36751d5573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -666,7 +666,28 @@ public class AddonsManager {
* @since 1.8.0
*/
public void allLoaded() {
addons.forEach(Addon::allLoaded);
this.getEnabledAddons().forEach(this::allLoaded);
}
/**
* This method calls Addon#allLoaded in safe manner. If for some reason addon crashes on Addon#allLoaded, then
* it will disable itself without harming other addons.
* @param addon Addon that should trigger Addon#allLoaded method.
*/
private void allLoaded(@NonNull Addon addon) {
try {
addon.allLoaded();
} catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {
// Looks like the addon is incompatible, because it tries to refer to missing classes...
this.handleAddonIncompatibility(addon, e);
// Disable addon.
this.disable(addon);
} catch (Exception e) {
// Unhandled exception. We'll give a bit of debug here.
this.handleAddonError(addon, e);
// Disable addon.
this.disable(addon);
}
}
}