Uploaded image for project: 'Tapestry'
  1. Tapestry
  2. TAPESTRY-131

NullPointerException when initialising page property

Details

    • Bug
    • Status: Resolved
    • Resolution: Won't Fix
    • 3.0
    • None
    • Framework
    • None
    • Operating System: Other
      Platform: Other
    • 27608

    Description

      I got a null pointer exception with the following (partial) stack trace:

      org.apache.tapestry.Tapestry.fireObservedChange(Tapestry.java:1373)
      org.apache.tapestry.AbstractComponent.fireObservedChange
      (AbstractComponent.java:345)
      se.elevance.timer.web.EditTaskPage$Enhance_0.setTask
      (EditTaskPage$Enhance_0.java)
      se.elevance.timer.web.EditTaskPage.initialize(EditTaskPage.java:35)
      org.apache.tapestry.AbstractPage.<init>(AbstractPage.java:165)
      org.apache.tapestry.html.BasePage.<init>(BasePage.java:73)
      se.elevance.timer.web.EditTaskPage.<init>(EditTaskPage.java:31)
      se.elevance.timer.web.EditTaskPage$Enhance_0.<init>
      (EditTaskPage$Enhance_0.java)
      sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      sun.reflect.NativeConstructorAccessorImpl.newInstance
      (NativeConstructorAccessorImpl.java:39)

      It appears that the following line in Tapestry.java is the problem:

      ChangeObserver observer = component.getPage().getChangeObserver();

      Looking a bit into the code, it would seem that component.getPage() returns
      null for a page. I can see two possible ways to solve this:

      1. modify the AbstractPage() constructor to:
      public AbstractPage()

      { setPage(this); initialize(); }

      2. Modify the fireObservedChange() methods along the following lines:
      public static void fireObservedChange(
      IComponent component,
      String propertyName,
      Object newValue)
      {
      IPage page = component.getPage(); // will be null for a page

      if (component instanceof IPage)

      { // maybe only overwrite page if it is in fact null? page = (IPage) component; }

      ChangeObserver observer = page.getChangeObserver();

      if (observer == null)
      return;

      ObservedChangeEvent event = new ObservedChangeEvent(component,
      propertyName, newValue);

      observer.observeChange(event);
      }

      I don't know what the side effects would be of either alternative. In my case,
      the page specification contains the following and the line in
      EditTaskPage.initialize() that is the cause for the exception is a call to
      setTask(null) - which I think should be no problem.

      <property-specification name="task"
      type="se.elevance.timer.data.Task" persistent="yes" />

      Attachments

        Activity

          People

            Unassigned Unassigned
            petter.mahlen@chello.se Petter Måhlén
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment