You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Izak Wessels <po...@gmail.com> on 2006/02/06 09:54:19 UTC

compareTo() NullPointer Exception Problem using Session

Hello all,

In my current application I have the requirement to implement a cart of
Quotation Products. The cart cannot contain duplicate elements, hence the
need to define the cart as TreeSet. I have implemented compareTo(), equals()
and hashCode() for the type of objects that are going to be stored in the
cart, but for some reason I when I try to add a second item to my cart I get
the following exception :

-----------------------------------------------------
org.apache.tapestry.BindingException
Exception invoking listener method addToCart of component
QuotationSupplierProductDetails: Failure invoking listener method 'public
net.pokkie.jupiter.tapestry.quotationsupplierproduct.QuotationSupplierProductCartPage
net.pokkie.jupiter.tapestry.quotationsupplierproduct.QuotationSupplierProductDetailsPage.addToCart()'
on
$QuotationSupplierProductDetailsPage_37@cc357d[QuotationSupplierProductDetails]:
java.lang.NullPointerException
binding:     org.apache.tapestry.binding.ListenerMethodBinding@c31811[parameter
listener, component=QuotationSupplierProductDetails, methodName=addToCart,
location=context:/WEB-INF/QuotationSupplierProductDetails.page, line 61,
column 59]
component:
 $QuotationSupplierProductDetailsPage_37@cc357d[QuotationSupplierProductDetails]
location:     context:/WEB-INF/QuotationSupplierProductDetails.page, line
61, column 59

60    <component id="addToCart" type="Submit">
61    <binding name="listener" value="listener:addToCart"/>
62    </component>
63
64    <component id="continueShopping" type="Submit">
65    <binding name="listener" value="listener:continueShopping"/>
66    </component>

org.apache.hivemind.ApplicationRuntimeException
Failure invoking listener method 'public
net.pokkie.jupiter.tapestry.quotationsupplierproduct.QuotationSupplierProductCartPage
net.pokkie.jupiter.tapestry.quotationsupplierproduct.QuotationSupplierProductDetailsPage.addToCart()'
on
$QuotationSupplierProductDetailsPage_37@cc357d[QuotationSupplierProductDetails]:
java.lang.NullPointerException
component:
 $QuotationSupplierProductDetailsPage_37@cc357d[QuotationSupplierProductDetails]
location:     context:/WEB-INF/QuotationSupplierProductDetails.page, line 6,
column 118
1    <?xml version="1.0"?>
2    <!DOCTYPE page-specification PUBLIC
3    "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
4    "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
5
6    <page-specification class="
net.pokkie.jupiter.tapestry.quotationsupplierproduct.QuotationSupplierProductDetailsPage
">
7
8
9    <inject property="agent" type="state" object="agent"/>
10    <inject property="quotationProductCart" type="state"
object="quotationProductCart"/>
11

java.lang.NullPointerException
Stack Trace:

    * net.pokkie.jupiter.model.quotationproduct.QuotationProduct.compareTo(
QuotationProduct.java:196)
    * java.util.TreeMap.compare(TreeMap.java:1093)
    * java.util.TreeMap.put(TreeMap.java:465)
    * java.util.TreeSet.add(TreeSet.java:210)
    *
net.pokkie.jupiter.tapestry.quotationsupplierproduct.QuotationSupplierProductDetailsPage.addToCart
(QuotationSupplierProductDetailsPage.java:116)
    * sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    * sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
    * sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
    * java.lang.reflect.Method.invoke(Method.java:585)
    *
org.apache.tapestry.listener.ListenerMethodInvokerImpl.invokeTargetMethod(
ListenerMethodInvokerImpl.java:214)
    *
org.apache.tapestry.listener.ListenerMethodInvokerImpl.invokeListenerMethod(
ListenerMethodInvokerImpl.java:155)
    * org.apache.tapestry.listener.ListenerMethodInvokerImpl.searchAndInvoke
(ListenerMethodInvokerImpl.java:124)
    *
org.apache.tapestry.listener.ListenerMethodInvokerImpl.invokeListenerMethod(
ListenerMethodInvokerImpl.java:65)
    * org.apache.tapestry.listener.SyntheticListener.actionTriggered(
SyntheticListener.java:51)
    * org.apache.tapestry.binding.ListenerMethodBinding.actionTriggered(
ListenerMethodBinding.java:77)
    * org.apache.tapestry.listener.ListenerInvokerTerminator.invokeListener(
ListenerInvokerTerminator.java:51)
    *
$ListenerInvoker_1093b995c1a.invokeListener($ListenerInvoker_1093b995c1a.java)
    * org.apache.tapestry.form.AbstractSubmit.handleClick(
AbstractSubmit.java:81)
    * org.apache.tapestry.form.AbstractSubmit.rewindFormComponent(
AbstractSubmit.java:49)
    * org.apache.tapestry.form.AbstractFormComponent.renderComponent(
AbstractFormComponent.java:115)
    * org.apache.tapestry.AbstractComponent.render(AbstractComponent.java
:617)
    * org.apache.tapestry.AbstractComponent.renderBody(
AbstractComponent.java:434)
    * org.apache.tapestry.form.FormSupportImpl.rewind(FormSupportImpl.java
:564)
    * org.apache.tapestry.form.Form.renderComponent(Form.java:226)
    * org.apache.tapestry.AbstractComponent.render(AbstractComponent.java
:617)
    * org.apache.tapestry.form.Form.rewind(Form.java:327)
    * org.apache.tapestry.engine.RequestCycle.rewindForm(RequestCycle.java
:439)
    * org.apache.tapestry.form.Form.trigger(Form.java:338)
    * org.apache.tapestry.engine.DirectService.triggerComponent(
DirectService.java:146)
    * org.apache.tapestry.engine.DirectService.service(DirectService.java
:132)
    * $IEngineService_1093b995c72.service($IEngineService_1093b995c72.java)
    * org.apache.tapestry.services.impl.EngineServiceOuterProxy.service(
EngineServiceOuterProxy.java:66)
    * org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java
:248)
    * org.apache.tapestry.services.impl.InvokeEngineTerminator.service(
InvokeEngineTerminator.java:60)
    *
$WebRequestServicer_1093b995c50.service($WebRequestServicer_1093b995c50.java)
    *
$WebRequestServicer_1093b995c4c.service($WebRequestServicer_1093b995c4c.java)
    *
org.apache.tapestry.services.impl.WebRequestServicerPipelineBridge.service(
WebRequestServicerPipelineBridge.java:56)
    *
$ServletRequestServicer_1093b995c30.service($ServletRequestServicer_1093b995c30.java)
    * org.apache.tapestry.request.DecodedRequestInjector.service(
DecodedRequestInjector.java:55)
    *
$ServletRequestServicerFilter_1093b995c2c.service($ServletRequestServicerFilter_1093b995c2c.java)
    *
$ServletRequestServicer_1093b995c32.service($ServletRequestServicer_1093b995c32.java)
    * org.apache.tapestry.multipart.MultipartDecoderFilter.service(
MultipartDecoderFilter.java:52)
    *
$ServletRequestServicerFilter_1093b995c2a.service($ServletRequestServicerFilter_1093b995c2a.java)
    *
$ServletRequestServicer_1093b995c32.service($ServletRequestServicer_1093b995c32.java)
    * org.apache.tapestry.services.impl.SetupRequestEncoding.service(
SetupRequestEncoding.java:53)
    *
$ServletRequestServicerFilter_1093b995c2e.service($ServletRequestServicerFilter_1093b995c2e.java)
    *
$ServletRequestServicer_1093b995c32.service($ServletRequestServicer_1093b995c32.java)
    *
$ServletRequestServicer_1093b995c24.service($ServletRequestServicer_1093b995c24.java)
    * org.apache.tapestry.ApplicationServlet.doService(
ApplicationServlet.java:123)
    * org.apache.tapestry.ApplicationServlet.doPost(ApplicationServlet.java
:168)
    * javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    * javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    * org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
ApplicationFilterChain.java:252)
    * org.apache.catalina.core.ApplicationFilterChain.doFilter(
ApplicationFilterChain.java:173)
    * org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(
ReplyHeaderFilter.java:81)
    * org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
ApplicationFilterChain.java:202)
    * org.apache.catalina.core.ApplicationFilterChain.doFilter(
ApplicationFilterChain.java:173)
    * org.apache.catalina.core.StandardWrapperValve.invoke(
StandardWrapperValve.java:213)
    * org.apache.catalina.core.StandardContextValve.invoke(
StandardContextValve.java:178)
    * org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(
CustomPrincipalValve.java:39)
    * org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(
SecurityAssociationValve.java:159)
    * org.jboss.web.tomcat.security.JaccContextValve.invoke(
JaccContextValve.java:59)
    * org.apache.catalina.core.StandardHostValve.invoke(
StandardHostValve.java:126)
    * org.apache.catalina.valves.ErrorReportValve.invoke(
ErrorReportValve.java:105)
    * org.apache.catalina.core.StandardEngineValve.invoke(
StandardEngineValve.java:107)
    * org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java
:148)
    * org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:856)
    *
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection
(Http11Protocol.java:744)
    * org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(
PoolTcpEndpoint.java:527)
    * org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(
MasterSlaveWorkerThread.java:112)
    * java.lang.Thread.run(Thread.java:595)
-----------------------------------------------------

If I set my Application State Object (QuotationProductCart) to be of class "
java.util.ArrayList" then it works fine.


Thanks in advance

-- Pokkkie

Re: compareTo() NullPointer Exception Problem using Session

Posted by Apache <ap...@ss78.shared.server-system.net>.
You got it :-)!

On Mon, 2006-02-06 at 12:16 +0200, Izak Wessels wrote:
> t the quotation as my Application State Object so
> that I can access it in my cart,
> and thus avoid the NullPointer excep


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


-------------------- m2f --------------------

Sent from www.TapestryForums.com

Read this topic online here: <<topic_link>>

http://www.tapestryforums.com/viewtopic.php?p=14281#14281

-------------------- m2f --------------------





---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: compareTo() NullPointer Exception Problem using Session

Posted by Izak Wessels <po...@gmail.com>.
Rudolf,

Yup your right, that might be an even better solution.

Thanks

On 2/6/06, Rudolf Baloun <Ru...@atron.de> wrote:
>
> I think that you got no tapestry problem.
> You could do it like your discribed it or add an if-condition, to
> catch the other state:
>
> if(this.quatation != null){
>        // compare the quatation
> } else {
>     // do nothing
> }
>
> It depends on your business-logic...
>
>
> Izak Wessels wrote:
>
> >Hey Stijn,
> >
> >thanks for you reply. here is the code is snippet of my compareTo()
> method :
> >
> >    private Quotation_IF quotation;
> >    private SupplierProduct_IF supplierProduct;
> >
> >    /**
> >     *
> >     */
> >
> >
> >    public int compareTo(Object object){
> >
> >      log.debug("compareTo Initiated");
> >
> >        if(!(object instanceof QuotationProduct_IF)) {
> >            throw new ClassCastException();
> >        }
> >
> >        final QuotationProduct_IF quotationProduct =
> >(QuotationProduct_IF)object;
> >        final int EQUAL = 0;
> >
> >        //this optimization is usually worthwhile, and can
> >        //always be added
> >        if ( this == quotationProduct ) return EQUAL;
> >
> >        //objects, including type-safe enums, follow this form
> >        //note that null objects will throw an exception here
> >196 -->        int comparison = this.quotation.compareTo(
> >quotationProduct.getQuotation());
> >        if ( comparison != EQUAL ) return comparison;
> >        comparison = this.supplierProduct.compareTo(
> >quotationProduct.getSupplierProduct());
> >        if ( comparison != EQUAL ) return comparison;
> >
> >        return EQUAL;
> >  }
> >
> >Ahhh, I just realized that at this point, quotation is actually null
> since
> >the quotation hasn't yet
> >been saved to the database at this point. I probably need to save  the
> >quotation in the database,
> >return the id and then set the quotation as my Application State Object
> so
> >that I can access it in my cart,
> >and thus avoid the NullPointer exception.
> >
> >What you think?
> >
> >-- Izak
> >
> >
> >On 2/6/06, Stijn Christiaens <st...@vub.ac.be> wrote:
> >
> >
> >>Hello Izak,
> >>
> >>could it be that you just have a bug in your compareTo method.
> >>This method is called when you use a TreeMap, but not when you use an
> >>ArrayList.
> >>Try looking at line 196 of QuotationProduct. Your problem should be on
> >>that line.
> >>
> >>Ciao,
> >>
> >>Stijn
> >>
> >>On Mon, 2006-02-06 at 10:54 +0200, Izak Wessels wrote:
> >>
> >>
> >>>java.lang.NullPointerException
> >>>Stack Trace:
> >>>
> >>>    *
> >>>net.pokkie.jupiter.model.quotationproduct.QuotationProduct.compareTo(
> >>>QuotationProduct.java:196)
> >>>    * java.util.TreeMap.compare(TreeMap.java:1093)
> >>>    * java.util.TreeMap.put(TreeMap.java:465)
> >>>    * java.util.TreeSet.add(TreeSet.java:210)
> >>>
> >>>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>
> >>
> >>
> >>
> >
> >
> >
>
>
>

Re: compareTo() NullPointer Exception Problem using Session

Posted by Rudolf Baloun <Ru...@atron.de>.
I think that you got no tapestry problem.
You could do it like your discribed it or add an if-condition, to
catch the other state:

if(this.quatation != null){
       // compare the quatation
} else {
    // do nothing
}

It depends on your business-logic...


Izak Wessels wrote:

>Hey Stijn,
>
>thanks for you reply. here is the code is snippet of my compareTo() method :
>
>    private Quotation_IF quotation;
>    private SupplierProduct_IF supplierProduct;
>
>    /**
>     *
>     */
>
>
>    public int compareTo(Object object){
>
>      log.debug("compareTo Initiated");
>
>        if(!(object instanceof QuotationProduct_IF)) {
>            throw new ClassCastException();
>        }
>
>        final QuotationProduct_IF quotationProduct =
>(QuotationProduct_IF)object;
>        final int EQUAL = 0;
>
>        //this optimization is usually worthwhile, and can
>        //always be added
>        if ( this == quotationProduct ) return EQUAL;
>
>        //objects, including type-safe enums, follow this form
>        //note that null objects will throw an exception here
>196 -->        int comparison = this.quotation.compareTo(
>quotationProduct.getQuotation());
>        if ( comparison != EQUAL ) return comparison;
>        comparison = this.supplierProduct.compareTo(
>quotationProduct.getSupplierProduct());
>        if ( comparison != EQUAL ) return comparison;
>
>        return EQUAL;
>  }
>
>Ahhh, I just realized that at this point, quotation is actually null since
>the quotation hasn't yet
>been saved to the database at this point. I probably need to save  the
>quotation in the database,
>return the id and then set the quotation as my Application State Object so
>that I can access it in my cart,
>and thus avoid the NullPointer exception.
>
>What you think?
>
>-- Izak
>
>
>On 2/6/06, Stijn Christiaens <st...@vub.ac.be> wrote:
>  
>
>>Hello Izak,
>>
>>could it be that you just have a bug in your compareTo method.
>>This method is called when you use a TreeMap, but not when you use an
>>ArrayList.
>>Try looking at line 196 of QuotationProduct. Your problem should be on
>>that line.
>>
>>Ciao,
>>
>>Stijn
>>
>>On Mon, 2006-02-06 at 10:54 +0200, Izak Wessels wrote:
>>    
>>
>>>java.lang.NullPointerException
>>>Stack Trace:
>>>
>>>    *
>>>net.pokkie.jupiter.model.quotationproduct.QuotationProduct.compareTo(
>>>QuotationProduct.java:196)
>>>    * java.util.TreeMap.compare(TreeMap.java:1093)
>>>    * java.util.TreeMap.put(TreeMap.java:465)
>>>    * java.util.TreeSet.add(TreeSet.java:210)
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>  
>


Re: compareTo() NullPointer Exception Problem using Session

Posted by Stijn Christiaens <st...@vub.ac.be>.
You got it :-)!

On Mon, 2006-02-06 at 12:16 +0200, Izak Wessels wrote:
> t the quotation as my Application State Object so
> that I can access it in my cart,
> and thus avoid the NullPointer excep


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: compareTo() NullPointer Exception Problem using Session

Posted by Izak Wessels <po...@gmail.com>.
Hey Stijn,

thanks for you reply. here is the code is snippet of my compareTo() method :

    private Quotation_IF quotation;
    private SupplierProduct_IF supplierProduct;

    /**
     *
     */


    public int compareTo(Object object){

      log.debug("compareTo Initiated");

        if(!(object instanceof QuotationProduct_IF)) {
            throw new ClassCastException();
        }

        final QuotationProduct_IF quotationProduct =
(QuotationProduct_IF)object;
        final int EQUAL = 0;

        //this optimization is usually worthwhile, and can
        //always be added
        if ( this == quotationProduct ) return EQUAL;

        //objects, including type-safe enums, follow this form
        //note that null objects will throw an exception here
196 -->        int comparison = this.quotation.compareTo(
quotationProduct.getQuotation());
        if ( comparison != EQUAL ) return comparison;
        comparison = this.supplierProduct.compareTo(
quotationProduct.getSupplierProduct());
        if ( comparison != EQUAL ) return comparison;

        return EQUAL;
  }

Ahhh, I just realized that at this point, quotation is actually null since
the quotation hasn't yet
been saved to the database at this point. I probably need to save  the
quotation in the database,
return the id and then set the quotation as my Application State Object so
that I can access it in my cart,
and thus avoid the NullPointer exception.

What you think?

-- Izak


On 2/6/06, Stijn Christiaens <st...@vub.ac.be> wrote:
>
> Hello Izak,
>
> could it be that you just have a bug in your compareTo method.
> This method is called when you use a TreeMap, but not when you use an
> ArrayList.
> Try looking at line 196 of QuotationProduct. Your problem should be on
> that line.
>
> Ciao,
>
> Stijn
>
> On Mon, 2006-02-06 at 10:54 +0200, Izak Wessels wrote:
> > java.lang.NullPointerException
> > Stack Trace:
> >
> >     *
> > net.pokkie.jupiter.model.quotationproduct.QuotationProduct.compareTo(
> > QuotationProduct.java:196)
> >     * java.util.TreeMap.compare(TreeMap.java:1093)
> >     * java.util.TreeMap.put(TreeMap.java:465)
> >     * java.util.TreeSet.add(TreeSet.java:210)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: compareTo() NullPointer Exception Problem using Session

Posted by Stijn Christiaens <st...@vub.ac.be>.
Hello Izak,

could it be that you just have a bug in your compareTo method.
This method is called when you use a TreeMap, but not when you use an
ArrayList.
Try looking at line 196 of QuotationProduct. Your problem should be on
that line.

Ciao,

Stijn

On Mon, 2006-02-06 at 10:54 +0200, Izak Wessels wrote:
> java.lang.NullPointerException
> Stack Trace:
> 
>     *
> net.pokkie.jupiter.model.quotationproduct.QuotationProduct.compareTo(
> QuotationProduct.java:196)
>     * java.util.TreeMap.compare(TreeMap.java:1093)
>     * java.util.TreeMap.put(TreeMap.java:465)
>     * java.util.TreeSet.add(TreeSet.java:210)


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org