HBASE-2905 NPE when inserting mass data via REST interface

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@983699 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2010-08-09 15:55:19 +00:00
parent af09891840
commit a95f1ed4f6
3 changed files with 14 additions and 12 deletions

View File

@ -472,6 +472,8 @@ Release 0.21.0 - Unreleased
HBASE-2823 Entire Row Deletes not stored in Row+Col Bloom HBASE-2823 Entire Row Deletes not stored in Row+Col Bloom
(Alexander Georgiev via Stack) (Alexander Georgiev via Stack)
HBASE-2897 RowResultGenerator should handle NoSuchColumnFamilyException HBASE-2897 RowResultGenerator should handle NoSuchColumnFamilyException
HBASE-2905 NPE when inserting mass data via REST interface (Sandy Yin via
Andrew Purtell)
IMPROVEMENTS IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable HBASE-1760 Cleanup TODOs in HTable

View File

@ -24,8 +24,6 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Map;
import java.util.WeakHashMap;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
@ -47,7 +45,7 @@ import org.apache.hadoop.hbase.rest.Constants;
public class PlainTextMessageBodyProducer public class PlainTextMessageBodyProducer
implements MessageBodyWriter<Object> { implements MessageBodyWriter<Object> {
private Map<Object, byte[]> buffer = new WeakHashMap<Object, byte[]>(); private ThreadLocal<byte[]> buffer = new ThreadLocal<byte[]>();
@Override @Override
public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2,
@ -59,7 +57,7 @@ public class PlainTextMessageBodyProducer
public long getSize(Object object, Class<?> type, Type genericType, public long getSize(Object object, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) { Annotation[] annotations, MediaType mediaType) {
byte[] bytes = object.toString().getBytes(); byte[] bytes = object.toString().getBytes();
buffer.put(object, bytes); buffer.set(bytes);
return bytes.length; return bytes.length;
} }
@ -68,6 +66,8 @@ public class PlainTextMessageBodyProducer
Annotation[] annotations, MediaType mediaType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream outStream) MultivaluedMap<String, Object> httpHeaders, OutputStream outStream)
throws IOException, WebApplicationException { throws IOException, WebApplicationException {
outStream.write(buffer.remove(object)); byte[] bytes = buffer.get();
outStream.write(bytes);
buffer.remove();
} }
} }

View File

@ -25,8 +25,6 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Map;
import java.util.WeakHashMap;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
@ -49,7 +47,7 @@ import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
public class ProtobufMessageBodyProducer public class ProtobufMessageBodyProducer
implements MessageBodyWriter<ProtobufMessageHandler> { implements MessageBodyWriter<ProtobufMessageHandler> {
private Map<Object, byte[]> buffer = new WeakHashMap<Object, byte[]>(); private ThreadLocal<byte[]> buffer = new ThreadLocal<byte[]>();
@Override @Override
public boolean isWriteable(Class<?> type, Type genericType, public boolean isWriteable(Class<?> type, Type genericType,
@ -67,7 +65,7 @@ public class ProtobufMessageBodyProducer
return -1; return -1;
} }
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
buffer.put(m, bytes); buffer.set(bytes);
return bytes.length; return bytes.length;
} }
@ -75,6 +73,8 @@ public class ProtobufMessageBodyProducer
Annotation[] annotations, MediaType mediaType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException, WebApplicationException { throws IOException, WebApplicationException {
entityStream.write(buffer.remove(m)); byte[] bytes = buffer.get();
entityStream.write(bytes);
buffer.remove();
} }
} }