NullPointer Exception in RestS3Service

View: New views
2 Messages — Rating Filter:   Alert me  

NullPointer Exception in RestS3Service

by Jawahar Nayak :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 In the performRequest() method of Rests3Service class if any exception is thrown then it constructs the instance of S3Exception. Suppose if the network is disabled then the exception is thrown. In catch block it constructs the S3ServiceException

as

<Code>

s3ServiceException = new S3ServiceException("Request Error.", t);

s3ServiceException.setRequestVerb(httpMethod.getName());

s3ServiceException.setRequestPath(httpMethod.getPath());

s3ServiceException.setResponseCode(httpMethod.getStatusCode());
// This statement is throwing NullPointerException

s3ServiceException.setResponseStatus(httpMethod.getStatusText());
 
</Code>

The following is the exception
<Exception>

java.lang.NullPointerException
        at org.apache.commons.httpclient.HttpMethodBase.getStatusCode(HttpMethodBase.java:570)
        at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest(RestS3Service.java:1064)
        at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRestHead(RestS3Service.java:1637)
        at org.jets3t.service.impl.rest.httpclient.RestS3Service.getObjectImpl(RestS3Service.java:3373)
        at org.jets3t.service.impl.rest.httpclient.RestS3Service.getObjectDetailsImpl(RestS3Service.java:3245)
        at org.jets3t.service.S3Service.getObjectDetails(S3Service.java:1990)
        at org.jets3t.service.S3Service.getObjectDetails(S3Service.java:1335

</Exception>

if we are running upload, we always get

s3ServiceEventPerformed(CreateObjectsEvent event) {

// We always get event.getEventCode() == CreateObjectsEvent.EVENT_COMPLETED
 if the network is disabled.

}

I fixed the problem in this way.
          try{
                s3ServiceException.setResponseCode(httpMethod.getStatusCode());
            }catch(NullPointerException ne){
                s3ServiceException.setResponseCode(404);
            }

            try{
                s3ServiceException.setResponseStatus(httpMethod.getStatusText());
            }catch(NullPointerException ne){
                s3ServiceException.setResponseStatus("Network Problem");
            }

Its working for me.

Re: NullPointer Exception in RestS3Service

by James Murty-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have applied a fix for this issue and made the S3ServiceException error reporting a bit more accurate in general. When response information is not available, such as when there is no Internet access, the S3ServiceException class will not print out response attributes for which it has no meaningful information.

Thanks very much for the bug report and suggested fix.

James

---
http://www.jamesmurty.com


On Wed, Aug 26, 2009 at 10:59 PM, Jawahar Nayak <jlal@...> wrote:

 In the performRequest() method of Rests3Service class if any exception is
thrown then it constructs the instance of S3Exception. Suppose if the
network is disabled then the exception is thrown. In catch block it
constructs the S3ServiceException

as

<Code>

s3ServiceException = new S3ServiceException("Request Error.", t);

s3ServiceException.setRequestVerb(httpMethod.getName());

s3ServiceException.setRequestPath(httpMethod.getPath());

s3ServiceException.setResponseCode(httpMethod.getStatusCode());
// This statement is throwing NullPointerException

s3ServiceException.setResponseStatus(httpMethod.getStatusText());

</Code>

The following is the exception
<Exception>

java.lang.NullPointerException
       at
org.apache.commons.httpclient.HttpMethodBase.getStatusCode(HttpMethodBase.java:570)
       at
org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest(RestS3Service.java:1064)
       at
org.jets3t.service.impl.rest.httpclient.RestS3Service.performRestHead(RestS3Service.java:1637)
       at
org.jets3t.service.impl.rest.httpclient.RestS3Service.getObjectImpl(RestS3Service.java:3373)
       at
org.jets3t.service.impl.rest.httpclient.RestS3Service.getObjectDetailsImpl(RestS3Service.java:3245)
       at org.jets3t.service.S3Service.getObjectDetails(S3Service.java:1990)
       at org.jets3t.service.S3Service.getObjectDetails(S3Service.java:1335

</Exception>

if we are running upload, we always get

s3ServiceEventPerformed(CreateObjectsEvent event) {

// We always get event.getEventCode() == CreateObjectsEvent.EVENT_COMPLETED
 if the network is disabled.

}

I fixed the problem in this way.
         try{

s3ServiceException.setResponseCode(httpMethod.getStatusCode());
           }catch(NullPointerException ne){
               s3ServiceException.setResponseCode(404);
           }

           try{

s3ServiceException.setResponseStatus(httpMethod.getStatusText());
           }catch(NullPointerException ne){
               s3ServiceException.setResponseStatus("Network Problem");
           }

Its working for me.
--
View this message in context: http://www.nabble.com/NullPointer-Exception-in-RestS3Service-tp25166654p25166654.html
Sent from the JetS3t Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...