Hello,
I'm trying to develop a plugin that creates a spaces with a certain page tree in a specific order. For the last task I add a listener in the plugin for the CreateSpaceEvent. I managed to create the space, but when the listener detects the event and executes the java code it results in a java.lang.NullPointerException when it gets to this line:
log.warn("WARN: The homepage type is: " + homepage.getType());
The full method I am testing is:
@EventListener public void onSpaceCreateEvent(SpaceCreateEvent event){ Space mySpace = event.getSpace(); Page homepage = mySpace.getHomePage(); log.warn("WARN: The name is: " + mySpace.getName()); log.warn("WARN: The key is: " + mySpace.getKey()); log.warn("WARN: The homepage type is: " + homepage.getType()); }
The lines logging the space data execute successfully, but the one corresponding to the homepage throws the null pointer exception.
So, why could getHomePage return null?
Isn't the homepage created and assigned to the space when the SpaceCreateEvent is detected?
Thank you in advance.
Community moderators have prevented the ability to post new answers.
You inspect the mySpace object in the debugger.
If the homePage property is not initialized (NULL), then fetch the space again by its ID from spaceManager.
Thanks for your answer.
I tried now using spaceManager but I'm getting a java.lang.NullPointerException too:
Caused by: java.lang.NullPointerException at com.atlassian.confluence.plugins.hello_blueprint.MyBlueprintListener.onSpaceCreateEvent(MyBlueprintListener.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36) ... 268 more
Line 57 is
String x = this.spaceManager.getSpace(mySpace.getKey()).getName();
Apparently the spaceManager is NULL. Could it be the dependency injection is not working? Here is a snippet of my class, I wonder if the code is allright :
public class MyBlueprintListener { private static final Logger log = LoggerFactory.getLogger(MyBlueprintListener.class); private SpaceManager spaceManager; public void setSpaceManager(SpaceManager spaceManager) { this.spaceManager = spaceManager; } public MyBlueprintListener(EventPublisher eventPublisher) { eventPublisher.register(this); //demonstration only } @EventListener public void onSpaceCreateEvent(SpaceCreateEvent event){ log.warn("WARN: Created a SPACE."); Space mySpace = event.getSpace(); Page homepage = mySpace.getHomePage(); log.warn("WARN: The name is: " + mySpace.getName()); log.warn("WARN: The key is: " + mySpace.getKey()); String x = this.spaceManager.getSpace(mySpace.getKey()).getName(); log.warn("WARN: This space name is: " + x); } }
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.