Berin Loritsch wrote:
>Leif Mortenson wrote: > >>I was trying to get Logging configured by specifying a Configuration and >>a DefaultLogKitManager and ran into a NullPointerException because I had >>not called setLogger() on the DefaultLogKitManager before calling >>configure(). I figured out the problem after digging around in the code, >>but things would have been a lot easier had I gotten an >>IllegalStateException describing the problem or something along those lines. >> >>Following the examples in the docs, I have been trying to design my >>components to be fairly defensive about their own state by adding checks >>to make sure that say configure is not called before setLogger has been >>correctly called. >> > > >There is a utility class in Excalibur's Scratchpad that will help you >out. I am not at the right computer, so I can't give the full >class name now. It should be ComponentValidator or something like >that. > Thanks, yet the class is org.apache.avalon.excalibur.util.ComponentStateValidator. But if I am not mistaken. That is a class that can be used to track the state of a component that you make. It looks like you create an instance of the ComponentStateValidator in your component's constructor passing in the component's this reference. Then in each of your action methods, call the appropriate validator method. For example: public void compose(ComponentManager manager) throws ComponentException { m_validator.checkComposed(); ...user code... } It appears that this is a utility class to help make it easier for the components to protect themself. The problem that I ran into was that the DefaultLogKitManager does not defend itself from containers which do not follow the contracts correctly. In my case, this was caused by me creating a container at the same time as I was trying to learn how to do so. What is the coding standard for Avalon code? Are cases like this considered a problem in the Avalon class? Or are they only required to not throw NullPointerExceptions etc if the contacts are followed exactly? I vote for making the Avalon classes as rugged as possible in cases like this. Esp the classes which new users are most likely to be having to access directly from their own containers. Cheers, Leif >>What are peoples thoughts on this? I think that making these classes >>more defensive would also really help shorten the learning curve for new >>users by pointing out mistakes like mine without requiring the user to >>roll up their sleeves and dig into the code. >> >>Here is the exception that I got: >>java.lang.NullPointerException >>at >>org.apache.avalon.excalibur.logger.DefaultLogTargetFactoryManager.configure(DefaultLogTargetFactoryManager.java:144) >>at >>org.apache.avalon.excalibur.logger.DefaultLogKitManager.setupTargetFactoryManager(DefaultLogKitManager.java:191) >>at >>org.apache.avalon.excalibur.logger.DefaultLogKitManager.configure(DefaultLogKitManager.java:154) >>... rest of stack trace. >> >>Thrown on: >>if( getLogger().isDebugEnabled() ) >> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>