You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by siraj ahmed <si...@hurix.com> on 2007/06/21 15:03:02 UTC

problem

I am getting null pointer exception here, I think the code is correct 
then what is the problem

public Node getBlogEntryNode(String blogTitle, Session session)
            throws BlogApplicationException {
        if (_logger.isDebugEnabled())
            _logger.debug("Entering JackrabbitBlogEntryDAO.getNode() "
                    + blogTitle);
        Node blogEntry;
        try {
            Workspace workSpace = session.getWorkspace();
   
            QueryManager queryManager = workSpace.getQueryManager();

            StringBuffer queryStr = new StringBuffer("//blogEntry[@title 
= '");
            queryStr.append(blogTitle);
            queryStr.append("']");
       
            Query query = queryManager.createQuery(queryStr.toString(),
                    Query.XPATH);
           
               
            QueryResult queryResult = query.execute();
                         

            NodeIterator queryResultNodeIterator = queryResult.getNodes();
                           
           
           
           
        blogEntry = null;
            while (queryResultNodeIterator.hasNext()) {
                blogEntry = queryResultNodeIterator.nextNode();
            }
        } catch (InvalidQueryException e) {
            throw new BlogApplicationException(e);
        } catch (RepositoryException e) {
            throw new BlogApplicationException(e);
        }
        if (_logger.isDebugEnabled())
            _logger.debug("Exiting JackrabbitBlogEntryDAO.getNode() "
                    + blogEntry);
        return blogEntry;
    }

-----------------------------------------------------------
Hurix Mumbai telephone numbers have changed. New numbers are:

Mumbai 1: Simran Center -    +91 22 6677 4888

Mumbai 2: Solitiare Center - +91 22 6709 6888
===========================================================
***Disclaimer***


This email, and any attachments ("this email"), is confidential. If you are not the addressee
please tell the sender immediately, and destroy this email without using, sending or storing
it. Any opinions, express or implied, in this email, are those of the sender, and are not
necessarily approved by Hurix Systems. Except as expressly stated, this e-mail should not be
regarded as an offer, solicitation, recommendation or agreement to buy or sell products or
services, or to enter into any contract. E-mail transmissions are not secure and may suffer
errors, viruses, delay, interception and amendment. Hurix Systems does not accept liability
for damage caused by any of the foregoing.

HURIX SYSTEMS MAY MONITOR ALL INCOMING AND OUTGOING MAILS
============================================================

Re: problem

Posted by siraj ahmed <si...@hurix.com>.
yes, Its calling the method getBlogEntryNode and this methods return 
type getting null. thats the problem

public BlogEntryDTO getBlogEntry(String blogTitle)
            throws BlogApplicationException {
        BlogEntryDTO blogEntryDTO = null;
        if (_logger.isDebugEnabled())
            _logger.debug("Entering JackrabbitBlogEntryDAO.getBlogList() "
                    + blogTitle);
        try {

            Node blogEntry = getBlogEntryNode(blogTitle);
            String bloggerName = 
blogEntry.getProperty(PROP_BLOGAUTHOR).getString();
            String blogContent = 
blogEntry.getProperty(PROP_BLOGCONTENT).getString();
            Value creationTimeValue = (Value) blogEntry.getProperty(
                    PROP_CREATIONTIME).getValue();
            blogEntryDTO = new BlogEntryDTO(bloggerName, blogTitle,
                    blogContent, creationTimeValue.getDate());
        } catch (InvalidQueryException e) {
            throw new BlogApplicationException(e);
        } catch (ValueFormatException e) {
            throw new BlogApplicationException(e);
        } catch (PathNotFoundException e) {
            throw new BlogApplicationException(e);
        } catch (IllegalStateException e) {
            throw new BlogApplicationException(e);
        } catch (RepositoryException e) {
            throw new BlogApplicationException(e);
        }

        if (_logger.isDebugEnabled())
            _logger.debug("Exiting JackrabbitBlogEntryDAO.getBlogList() "
                    + blogEntryDTO);

        return blogEntryDTO;
    }

Jukka Zitting wrote:
> Hi,
>
> The exception you sent indicates that the problem is on line 171 of
> JackrabbitBlogEntryDAO.java, within the getBlogEntry method. The
> method you sent is getBlogEntryNode, not getBlogEntry. Even if you had
> sent the correct method body, without line number information it is
> hard to identify what the incorrect line is.
>
> Moreover, this really doesn't look like a Jackrabbit issue as your
> stack traces contain no org.apache.jackrabbit classes. I suspect you
> simply have an error in your code. Check out what you have on line 171
> and trace back all the references used on that line.
>
> BR,
>
> Jukka Zitting
>


-----------------------------------------------------------
Hurix Mumbai telephone numbers have changed. New numbers are:

Mumbai 1: Simran Center -    +91 22 6677 4888

Mumbai 2: Solitiare Center - +91 22 6709 6888
===========================================================
***Disclaimer***


This email, and any attachments ("this email"), is confidential. If you are not the addressee
please tell the sender immediately, and destroy this email without using, sending or storing
it. Any opinions, express or implied, in this email, are those of the sender, and are not
necessarily approved by Hurix Systems. Except as expressly stated, this e-mail should not be
regarded as an offer, solicitation, recommendation or agreement to buy or sell products or
services, or to enter into any contract. E-mail transmissions are not secure and may suffer
errors, viruses, delay, interception and amendment. Hurix Systems does not accept liability
for damage caused by any of the foregoing.

HURIX SYSTEMS MAY MONITOR ALL INCOMING AND OUTGOING MAILS
============================================================

Re: problem

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

The exception you sent indicates that the problem is on line 171 of
JackrabbitBlogEntryDAO.java, within the getBlogEntry method. The
method you sent is getBlogEntryNode, not getBlogEntry. Even if you had
sent the correct method body, without line number information it is
hard to identify what the incorrect line is.

Moreover, this really doesn't look like a Jackrabbit issue as your
stack traces contain no org.apache.jackrabbit classes. I suspect you
simply have an error in your code. Check out what you have on line 171
and trace back all the references used on that line.

BR,

Jukka Zitting

Re: problem

Posted by siraj ahmed <si...@hurix.com>.
*eption*

javax.servlet.ServletException
	org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

*root cause*

java.lang.NullPointerException
	com.onjava.blog.data.dao.impl.JackrabbitBlogEntryDAO.getBlogEntry(JackrabbitBlogEntryDAO.java:171)
	com.onjava.blog.ui.action.EditBlogEntryForm.execute(EditBlogEntryForm.java:27)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



Felix Meschberger wrote:
> Hi Ahmed,
>
> Not sure, where exactly you get the NullPointerException. You should 
> be more
> specific. Thanks.
>
> Regards
> Felix
>
> On 6/21/07, siraj ahmed <si...@hurix.com> wrote:
>>
>>
>> I am getting null pointer exception here, I think the code is correct
>> then what is the problem
>>
>> public Node getBlogEntryNode(String blogTitle, Session session)
>>             throws BlogApplicationException {
>>         if (_logger.isDebugEnabled())
>>             _logger.debug("Entering JackrabbitBlogEntryDAO.getNode() "
>>                     + blogTitle);
>>         Node blogEntry;
>>         try {
>>             Workspace workSpace = session.getWorkspace();
>>
>>             QueryManager queryManager = workSpace.getQueryManager();
>>
>>             StringBuffer queryStr = new StringBuffer("//blogEntry[@title
>> = '");
>>             queryStr.append(blogTitle);
>>             queryStr.append("']");
>>
>>             Query query = queryManager.createQuery(queryStr.toString(),
>>                     Query.XPATH);
>>
>>
>>             QueryResult queryResult = query.execute();
>>
>>
>>             NodeIterator queryResultNodeIterator = 
>> queryResult.getNodes();
>>
>>
>>
>>
>>         blogEntry = null;
>>             while (queryResultNodeIterator.hasNext()) {
>>                 blogEntry = queryResultNodeIterator.nextNode();
>>             }
>>         } catch (InvalidQueryException e) {
>>             throw new BlogApplicationException(e);
>>         } catch (RepositoryException e) {
>>             throw new BlogApplicationException(e);
>>         }
>>         if (_logger.isDebugEnabled())
>>             _logger.debug("Exiting JackrabbitBlogEntryDAO.getNode() "
>>                     + blogEntry);
>>         return blogEntry;
>>     }
>>
>> -----------------------------------------------------------
>> Hurix Mumbai telephone numbers have changed. New numbers are:
>>
>> Mumbai 1: Simran Center -    +91 22 6677 4888
>>
>> Mumbai 2: Solitiare Center - +91 22 6709 6888
>> ===========================================================
>> ***Disclaimer***
>>
>>
>> This email, and any attachments ("this email"), is confidential. If you
>> are not the addressee
>> please tell the sender immediately, and destroy this email without 
>> using,
>> sending or storing
>> it. Any opinions, express or implied, in this email, are those of the
>> sender, and are not
>> necessarily approved by Hurix Systems. Except as expressly stated, this
>> e-mail should not be
>> regarded as an offer, solicitation, recommendation or agreement to 
>> buy or
>> sell products or
>> services, or to enter into any contract. E-mail transmissions are not
>> secure and may suffer
>> errors, viruses, delay, interception and amendment. Hurix Systems 
>> does not
>> accept liability
>> for damage caused by any of the foregoing.
>>
>> HURIX SYSTEMS MAY MONITOR ALL INCOMING AND OUTGOING MAILS
>> ============================================================
>>
>


-----------------------------------------------------------
Hurix Mumbai telephone numbers have changed. New numbers are:

Mumbai 1: Simran Center -    +91 22 6677 4888

Mumbai 2: Solitiare Center - +91 22 6709 6888
===========================================================
***Disclaimer***


This email, and any attachments ("this email"), is confidential. If you are not the addressee
please tell the sender immediately, and destroy this email without using, sending or storing
it. Any opinions, express or implied, in this email, are those of the sender, and are not
necessarily approved by Hurix Systems. Except as expressly stated, this e-mail should not be
regarded as an offer, solicitation, recommendation or agreement to buy or sell products or
services, or to enter into any contract. E-mail transmissions are not secure and may suffer
errors, viruses, delay, interception and amendment. Hurix Systems does not accept liability
for damage caused by any of the foregoing.

HURIX SYSTEMS MAY MONITOR ALL INCOMING AND OUTGOING MAILS
============================================================

Re: problem

Posted by Felix Meschberger <Fe...@day.com>.
Hi Ahmed,

Not sure, where exactly you get the NullPointerException. You should be more
specific. Thanks.

Regards
Felix

On 6/21/07, siraj ahmed <si...@hurix.com> wrote:
>
>
> I am getting null pointer exception here, I think the code is correct
> then what is the problem
>
> public Node getBlogEntryNode(String blogTitle, Session session)
>             throws BlogApplicationException {
>         if (_logger.isDebugEnabled())
>             _logger.debug("Entering JackrabbitBlogEntryDAO.getNode() "
>                     + blogTitle);
>         Node blogEntry;
>         try {
>             Workspace workSpace = session.getWorkspace();
>
>             QueryManager queryManager = workSpace.getQueryManager();
>
>             StringBuffer queryStr = new StringBuffer("//blogEntry[@title
> = '");
>             queryStr.append(blogTitle);
>             queryStr.append("']");
>
>             Query query = queryManager.createQuery(queryStr.toString(),
>                     Query.XPATH);
>
>
>             QueryResult queryResult = query.execute();
>
>
>             NodeIterator queryResultNodeIterator = queryResult.getNodes();
>
>
>
>
>         blogEntry = null;
>             while (queryResultNodeIterator.hasNext()) {
>                 blogEntry = queryResultNodeIterator.nextNode();
>             }
>         } catch (InvalidQueryException e) {
>             throw new BlogApplicationException(e);
>         } catch (RepositoryException e) {
>             throw new BlogApplicationException(e);
>         }
>         if (_logger.isDebugEnabled())
>             _logger.debug("Exiting JackrabbitBlogEntryDAO.getNode() "
>                     + blogEntry);
>         return blogEntry;
>     }
>
> -----------------------------------------------------------
> Hurix Mumbai telephone numbers have changed. New numbers are:
>
> Mumbai 1: Simran Center -    +91 22 6677 4888
>
> Mumbai 2: Solitiare Center - +91 22 6709 6888
> ===========================================================
> ***Disclaimer***
>
>
> This email, and any attachments ("this email"), is confidential. If you
> are not the addressee
> please tell the sender immediately, and destroy this email without using,
> sending or storing
> it. Any opinions, express or implied, in this email, are those of the
> sender, and are not
> necessarily approved by Hurix Systems. Except as expressly stated, this
> e-mail should not be
> regarded as an offer, solicitation, recommendation or agreement to buy or
> sell products or
> services, or to enter into any contract. E-mail transmissions are not
> secure and may suffer
> errors, viruses, delay, interception and amendment. Hurix Systems does not
> accept liability
> for damage caused by any of the foregoing.
>
> HURIX SYSTEMS MAY MONITOR ALL INCOMING AND OUTGOING MAILS
> ============================================================
>

Re: problem

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 6/21/07, siraj ahmed <si...@hurix.com> wrote:
> [...]
>         blogEntry = null;
>             while (queryResultNodeIterator.hasNext()) {
>                 blogEntry = queryResultNodeIterator.nextNode();
>             }
> [...]
>         return blogEntry;

Assuming getBlogEntry() calls getBlogEntryNode(), then the error could
simply be that the search you are running returns no results which
causes getBlogEntryNode() to return the default blogEntry value, i.e.
null.

I would rather use code like this:

    if (queryResultNodeIterator.hasNext()) {
        return queryResultNodeIterator.nextNode();
    } else {
        throw new BlogEntryNotFoundException();
    }

BR,

Jukka Zitting