Wicket
  1. Wicket
  2. WICKET-5146

Application not destroyed if WicketFilter#init() fails

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.10, 6.7.0
    • Fix Version/s: 6.8.0, 1.5.11
    • Component/s: None
    • Labels:
      None

      Description

      WicketFilter calls Application#initApplication() which calls Application#init().

      In case of Exception thrown in the application's init() method, there is no cleanup in WicketFilter's finally block.

      The result of this is, in case where Wicket is in the application server's libraries (not deployed with the war file), that the application cannot be re-deployed withhout re-starting the application server.

      That is because Application#setName() crashes with IllegalStateException("Application name can only be set once.").

      In Application, private static final Map<String, Application> applicationKeyToApplication holds a reference to the crashed instance after the application is undeployed.

      1. fix-WICKET-5146-2.patch
        1 kB
        Cedric Gatay
      2. testcase.zip
        24 kB
        bernard

        Activity

        Hide
        Cedric Gatay added a comment -

        Could you provide a Quickstart regarding this issue please ?

        Show
        Cedric Gatay added a comment - Could you provide a Quickstart regarding this issue please ?
        Hide
        Cedric Gatay added a comment -

        You'll find a patch that should work around the issue you described. However, without a quickstart, it would be difficult to check if it is ok. Please test it and tell me if it works for you.

        Show
        Cedric Gatay added a comment - You'll find a patch that should work around the issue you described. However, without a quickstart, it would be difficult to check if it is ok. Please test it and tell me if it works for you.
        Hide
        bernard added a comment -

        Quick start.

        Show
        bernard added a comment - Quick start.
        Hide
        bernard added a comment -

        I have attached the quickstart as requested. But to reproduce the problem you have to deploy the app to the server in a way that the libraries are not deployed with it. You can do this by adding an attribute to the dependencies <scope>provided</scope>

        You could try this on an application server e.g. GlassFish that installs itself with NetBeans as follows:

        • Install the app server
        • copy wicket libraries to the domain's lib folder
        • Run the app with the exception in init()
        • Take out the exception, recompile and run again

        In the error scenario, private static final Map<String, Application> applicationKeyToApplication is not cleared. I don't know how the patch addresses this.

        Show
        bernard added a comment - I have attached the quickstart as requested. But to reproduce the problem you have to deploy the app to the server in a way that the libraries are not deployed with it. You can do this by adding an attribute to the dependencies <scope>provided</scope> You could try this on an application server e.g. GlassFish that installs itself with NetBeans as follows: Install the app server copy wicket libraries to the domain's lib folder Run the app with the exception in init() Take out the exception, recompile and run again In the error scenario, private static final Map<String, Application> applicationKeyToApplication is not cleared. I don't know how the patch addresses this.
        Hide
        Cedric Gatay added a comment -

        Thanks. I'll have a look at it. I think the way I fixed it the flag in the hash map will not be cleared but overwritten by the second deploy.

        Show
        Cedric Gatay added a comment - Thanks. I'll have a look at it. I think the way I fixed it the flag in the hash map will not be cleared but overwritten by the second deploy.
        Hide
        bernard added a comment -

        The hash map cannot be overwritten because it is final. I think you need to call Application#internalDestroy()

        Show
        bernard added a comment - The hash map cannot be overwritten because it is final. I think you need to call Application#internalDestroy()
        Hide
        Cedric Gatay added a comment -

        After testing against your test application, it appears that one need to call internalDestroy() as you stated in order to properly unregister the application from the static application hashmap.

        The attached fix-WICKET-5146-2.patch file include this update wrapped inside another try / catch block.

        Show
        Cedric Gatay added a comment - After testing against your test application, it appears that one need to call internalDestroy() as you stated in order to properly unregister the application from the static application hashmap. The attached fix- WICKET-5146 -2.patch file include this update wrapped inside another try / catch block.
        Hide
        Sven Meier added a comment -

        I changed the patch to call #destroy(), thus safely destroying the application factory too.

        Thanks Cedric.

        Show
        Sven Meier added a comment - I changed the patch to call #destroy(), thus safely destroying the application factory too. Thanks Cedric.

          People

          • Assignee:
            Sven Meier
            Reporter:
            bernard
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development