Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2045

FileUploadField.onDetach() causes IllegalStateException()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.4-RC1
    • 1.4-RC2
    • wicket
    • None
    • Linux ubuntu 2.6.24-23-generic #1 SMP Thu Nov 27 18:13:46 UTC 2008 x86_64 GNU/Linux
      java version "1.6.0_07"
      Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
      Java HotSpot(TM) 64-Bit Server VM (build 10.0-b23, mixed mode)

    Description

      This was detected when using the example/sample Upload demo locally.

      ERROR - RequestCycle - there was an error cleaning up target org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget@20665159[Page class = org.apache.wicket.examples.upload.UploadPage, id = 0, version = 0]>simpleUpload->interface org.apache.wicket.markup.html.form.IFormSubmitListener.IFormSubmitListener (request paramaters: [RequestParameters componentPath=0:simpleUpload pageMapName=null versionNumber=0 interfaceName=IFormSubmitListener componentId=null behaviorId=null urlDepth=-1 parameters={} onlyProcessIfPathActive=false]).
      java.lang.IllegalStateException: Attempt to set model object on null model of component: simpleUpload:fileInput
      at org.apache.wicket.Component.setDefaultModelObject(Component.java:2962)
      at org.apache.wicket.markup.html.form.FormComponent.setModelObject(FormComponent.java:1652)
      at org.apache.wicket.markup.html.form.upload.FileUploadField.onDetach(FileUploadField.java:175)

      Looking at the source indicates that unless onDetach() is over-ridden the default will always generate this exception. Here is the source for the FileUpLoadField.onDetach(). The line that creates the exception is noted by the "<<<HERE" in the snippet below.

      FileUpLoadField.onDetach() snippet:

      /**

      • Clean up at the end of the request. This means closing all inputstreams which might have been
      • opened from the fileUpload.
      • @see org.apache.wicket.Component#onDetach()
        */
        @Override
        protected void onDetach()
        Unknown macro: { if (fileUpload != null && forceCloseStreamsOnDetach()) { fileUpload.closeStreams(); fileUpload = null; setModelObject(null); <<<HERE } super.onDetach(); }

      Drilling further down, the setModelObject() calls FormComponent.setModelObject(), which in turns calls Component.setDefaultModelObject(). Inside setDefaultModelObject(), a check is done to see if the model object is null, if it is, it throws an exception:

      public final Component setDefaultModelObject(final Object object)
      {
      final IModel<Object> model = (IModel<Object>)getDefaultModel();

      // Check whether anything can be set at all
      if (model == null)

      { throw new IllegalStateException( "Attempt to set model object on null model of component: " + getPageRelativePath()); }

      ...
      }

      Attachments

        Activity

          People

            jdonnerstag Juegen Donnerstag
            athomson Andy Thomson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: