Don't use static initializers to load extensions

Description

As described in the forum, use of static initializers prevents extensions from being extended. This is because even if an extension class does not appear in smack-config.xml, if it is imported or otherwise referenced from another class (say, by a subclass that wants to modify an extension's behavior) that extension is still loaded via the static initializer. In many cases the initialization involves creating and attaching a packetListener or connectionListener that is difficult if not impossible to remove once it's been created. The end result is that it is not possible to subclass or otherwise modify extensions short of copying or reimplementing the code.

My proposal (on the forum link) modifies the extension mechanism slightly so there is an interface with an 'initialize' method that is explicitly called. This not only removes the 'automatic initialization as soon as the class loaded,' but it also allows code to override and extend an extension class using standard Java OOP practices.

I'll work on creating a patch and test case but wanted to create the issue for now. I believe it can be implemented in a backward-compatible manner with existing extensions. If there are any other concerns with this proposal please let me know.

Environment

None

Activity

Show:

Florian Schmaus February 12, 2015 at 8:57 AM

It usually comes down to: "If you think you need to subclass an Manager (with a static initializer), then you are doing something wrong".

Won't Fix

Details

Assignee

Reporter

Components

Affects versions

Priority

Created April 30, 2010 at 6:30 PM
Updated October 28, 2020 at 1:28 PM
Resolved February 12, 2015 at 8:57 AM