Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserList macro fires a NullPointerException due to conflict on WikiDescriptorManager field #160

Closed
slauriere opened this issue Aug 30, 2023 · 6 comments

Comments

@slauriere
Copy link
Contributor

Steps to reproduce

In a wiki page, insert the userList macro as follows:

{{userList properties="avatar,username,email,company,phone" users="XWiki.JohnDoe,XWiki.MaryJohn" fixedTableLayout="true"/}}

Expected result

The macro displays a table with the list of passed users.

Actual result

Exception:

java.lang.NullPointerException
 at com.xwiki.macros.AbstractProMacro.execute(AbstractProMacro.java:113)
 at org.xwiki.rendering.internal.transformation.macro.MacroTransformation.transform(MacroTransformation.java:309)
 at org.xwiki.rendering.internal.transformation.DefaultRenderingContext.transformInContext(DefaultRenderingContext.java:183)

See full stack trace:
exception.txt

@slauriere
Copy link
Contributor Author

As pointed out by @michitux, the issue is due to a conflict between AbstractProMacro and UserListMacro declaring both a field named wikiDescriptorManager. I'm adding a reference to a discusion on the #product chat on how to solve the issue (date: August 30 2023, 4:30pm) cc @snazare

@slauriere
Copy link
Contributor Author

slauriere commented Sep 6, 2023

Adding excerpts from the discussion on the #product chat:

  • It is due to AbstractProMacro and UserListMacro declaring a field named wikiDescriptorManager which confuses the ComponentManager (as confirmed by Thomas, this is not supported)
  • Anca points out that there is way too much private stuffs without getters in the abstract pro macro class for an abstract class
  • I asked whether we should rename the field in the inherited class to something different. Thomas replied it could be exposed as a protected field instead, and that it all depends if we want to expose that field as an API or not.
  • Anca points out that the fix would be to either make getters to those fields or to make it a protected field, or, if you don't want it to be API, look it up dynamically in the abstract pro macro function that needs it and use it then (scope it to the function that absolutely needs it, as a need of the function and not as a need of the class and superclasses)

@slauriere slauriere changed the title UserList macro fires a NullPointerException UserList macro fires a NullPointerException due to field conflict on WikiDescriptorManager Sep 6, 2023
@slauriere slauriere changed the title UserList macro fires a NullPointerException due to field conflict on WikiDescriptorManager UserList macro fires a NullPointerException due to conflict on WikiDescriptorManager field Sep 6, 2023
slauriere added a commit that referenced this issue Sep 6, 2023
…WikiDescriptorManager field

- Introduce getter in AbstractProMacro for field "wikiDescriptorManager"
- Use this getter in UserListMacro instead of declaring the same field
@slauriere slauriere self-assigned this Sep 6, 2023
@slauriere slauriere added this to the 1.9.3 milestone Sep 6, 2023
@slauriere
Copy link
Contributor Author

I introduced a getter for field wikiDescriptorManager in AbstractProMacro and updated UserListMacro to use that getter instead of declaring the same field locally. This updated version works successfully on my side with XWiki 15.6 (while I was able to reproduce the NullPointerException beforehand).

ccing @raphj since it seems the issue was introduced in c845afc

@raphj
Copy link
Contributor

raphj commented Sep 6, 2023

Thanks for the heads up and the fix @slauriere!

@slauriere
Copy link
Contributor Author

Also ccing @snazare just in case :-)

@snazare
Copy link

snazare commented Sep 7, 2023

thank you very much! We will plan a release soon :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants