Bug 51315 - Removing Valve from StandardContext causes IllegalArgumentException
Removing Valve from StandardContext causes IllegalArgumentException
Status: RESOLVED FIXED
Product: Tomcat 6
Classification: Unclassified
Component: Catalina
6.0.32
PC All
: P2 normal (vote)
: default
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2011-06-03 09:02 UTC by Violeta Georgieva
Modified: 2011-06-14 13:37 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Violeta Georgieva 2011-06-03 09:02:08 UTC
Hello,

I have the following scenario - runtime I want to remove one Valve from a specified StandardContext.

I'm using the following method:

org.apache.catalina.core.StandardContext.removeValve(Valve valve)

which invokes

org.apache.catalina.core.StandardPipeline.removeValve(Valve valve)


The problem is that the following exception is thrown:

Caused by: java.lang.IllegalArgumentException: Configuration error:  Must be attached to a Context
       at org.apache.catalina.authenticator.AuthenticatorBase.setContainer(AuthenticatorBase.java:277)
       at org.apache.catalina.core.StandardPipeline.removeValve(StandardPipeline.java:537)

It appears that setContainer is invoked with "null" which leads to this IlleagalArgumentException.

I want to propose the following change:

Index: AuthenticatorBase.java
===================================================================
--- AuthenticatorBase.java	(revision 1100912)
+++ AuthenticatorBase.java	(working copy)
@@ -273,7 +273,7 @@
      */
     public void setContainer(Container container) {
 
-        if (!(container instanceof Context))
+        if (container != null && !(container instanceof Context))
             throw new IllegalArgumentException
                 (sm.getString("authenticator.notContext"));
 
Please tell me if there is more appropriate way to remove a Valve if the one above that I'm describing is not the correct one.

Thanks in advance.
Regards
Violeta Georgieva
Comment 1 Mark Thomas 2011-06-03 18:15:21 UTC
You are doing exactly the right thing. That is a bug in 6.0.x (that is fixed in 7.0.x by the way).

I have proposed your patch for 6.0.x
Comment 2 Mark Thomas 2011-06-14 13:05:18 UTC
Thanks for the patch. It has been applied to 6.0.x and will be included in 6.0.33 onwards.
Comment 3 Violeta Georgieva 2011-06-14 13:16:29 UTC
(In reply to comment #2)
> Thanks for the patch. It has been applied to 6.0.x and will be included in
> 6.0.33 onwards.

Great!Thanks!
Comment 4 Violeta Georgieva 2011-06-14 13:26:43 UTC
(In reply to comment #2)
> Thanks for the patch. It has been applied to 6.0.x and will be included in
> 6.0.33 onwards.

I just checked the commit and the description of the problem is IAE not NPE :(

Index: changelog.xml
===================================================================
--- changelog.xml	(revision 1135555)
+++ changelog.xml	(working copy)
@@ -115,7 +115,7 @@
         than as a String. (markt)
       </fix>
       <fix>
-        <bug>51315</bug>: Fix NPE when removing an authenticator valve from a
+        <bug>51315</bug>: Fix IAE when removing an authenticator valve from a
         container. Patch provided by Violeta Georgieva. (markt)
       </fix>
       <fix>
Comment 5 Mark Thomas 2011-06-14 13:30:18 UTC
Corrected
Comment 6 Violeta Georgieva 2011-06-14 13:37:08 UTC
(In reply to comment #5)
> Corrected

Thanks