java.lang.NullPointerException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • The static initialisation order of the inner class in TypeCodec are not garanteed, and sometimes that causes the primitiveCodecs map to be initialised before LongCodec.instance is. it happens on oracle java8 travid ci build box, but if I ran that {code} public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { Class<?> longCodec = Class.forName("com.datastax.driver.core.TypeCodec$LongCodec"); Field f = Class.forName("com.datastax.driver.core.TypeCodec").getDeclaredField("primitiveCodecs"); f.setAccessible(true); System.out.println("primitiveCodecs = " + f.get(null)); } {code} then it happens all the time {code} primitiveCodecs = {ascii=com.datastax.driver.core.TypeCodec$StringCodec@2e0fa5d3, bigint=null, blob=com.datastax.driver.core.TypeCodec$BytesCodec@5010be6, boolean=com.datastax.driver.core.TypeCodec$BooleanCodec@685f4c2e, counter=null, decimal=com.datastax.driver.core.TypeCodec$DecimalCodec@7daf6ecc, double=com.datastax.driver.core.TypeCodec$DoubleCodec@2e5d6d97, float=com.datastax.driver.core.TypeCodec$FloatCodec@238e0d81, inet=com.datastax.driver.core.TypeCodec$InetCodec@31221be2, int=com.datastax.driver.core.TypeCodec$IntCodec@377dca04, text=com.datastax.driver.core.TypeCodec$StringCodec@728938a9, timestamp=com.datastax.driver.core.TypeCodec$DateCodec@21b8d17c, uuid=com.datastax.driver.core.TypeCodec$UUIDCodec@6433a2, varchar=com.datastax.driver.core.TypeCodec$StringCodec@728938a9, varint=com.datastax.driver.core.TypeCodec$BigIntegerCodec@5910e440, timeuuid=com.datastax.driver.core.TypeCodec$TimeUUIDCodec@6267c3bb, custom=com.datastax.driver.core.TypeCodec$BytesCodec@5010be6} {code} the primitiveCodecs should not depends on the static initialisers, it could instead create the instance itself. during the build I then get the following error {code} testInsertDbObjects(org.sfm.datastax.SettableDataMapperTest) Time elapsed: 0.089 sec <<< ERROR! java.lang.NullPointerException: null at com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:209) at com.datastax.driver.core.DefaultPreparedStatement.bind(DefaultPreparedStatement.java:103) at org.sfm.datastax.SettableDataMapperTest.checkObjectInserted(SettableDataMapperTest.java:45) {code} or {code} testMapSetUDT(org.sfm.datastax.DatastaxMapperCollectionTest) Time elapsed: 0.331 sec <<< ERROR! java.lang.NullPointerException: null at com.datastax.driver.core.DataType.deserialize(DataType.java:673) at com.datastax.driver.core.AbstractData.hashCode(AbstractData.java:457) at com.datastax.driver.core.UDTValue.hashCode(UDTValue.java:69) at java.util.HashMap.hash(HashMap.java:338) at java.util.HashMap.put(HashMap.java:611) at java.util.HashSet.add(HashSet.java:219) at com.datastax.driver.core.TypeCodec$SetCodec.deserialize(TypeCodec.java:1076) at com.datastax.driver.core.TypeCodec$SetCodec.deserialize(TypeCodec.java:1001) at com.datastax.driver.core.AbstractGettableByIndexData.getSet(AbstractGettableByIndexData.java:343) at com.datastax.driver.core.AbstractGettableData.getSet(AbstractGettableData.java:26) at org.sfm.datastax.impl.getter.DatastaxSetWithConverterGetter.get(DatastaxSetWithConverterGetter.java:24) at org.sfm.datastax.impl.getter.DatastaxSetWithConverterGetter.get(DatastaxSetWithConverterGetter.java:10) at org.sfm.map.impl.fieldmapper.FieldMapperImpl.mapTo(FieldMapperImpl.java:23) {code} see https://travis-ci.org/arnaudroger/SimpleFlatMapper/jobs/83902196
    via by Arnaud Roger,
  • The static initialisation order of the inner class in TypeCodec are not garanteed, and sometimes that causes the primitiveCodecs map to be initialised before LongCodec.instance is. it happens on oracle java8 travid ci build box, but if I ran that {code} public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { Class<?> longCodec = Class.forName("com.datastax.driver.core.TypeCodec$LongCodec"); Field f = Class.forName("com.datastax.driver.core.TypeCodec").getDeclaredField("primitiveCodecs"); f.setAccessible(true); System.out.println("primitiveCodecs = " + f.get(null)); } {code} then it happens all the time {code} primitiveCodecs = {ascii=com.datastax.driver.core.TypeCodec$StringCodec@2e0fa5d3, bigint=null, blob=com.datastax.driver.core.TypeCodec$BytesCodec@5010be6, boolean=com.datastax.driver.core.TypeCodec$BooleanCodec@685f4c2e, counter=null, decimal=com.datastax.driver.core.TypeCodec$DecimalCodec@7daf6ecc, double=com.datastax.driver.core.TypeCodec$DoubleCodec@2e5d6d97, float=com.datastax.driver.core.TypeCodec$FloatCodec@238e0d81, inet=com.datastax.driver.core.TypeCodec$InetCodec@31221be2, int=com.datastax.driver.core.TypeCodec$IntCodec@377dca04, text=com.datastax.driver.core.TypeCodec$StringCodec@728938a9, timestamp=com.datastax.driver.core.TypeCodec$DateCodec@21b8d17c, uuid=com.datastax.driver.core.TypeCodec$UUIDCodec@6433a2, varchar=com.datastax.driver.core.TypeCodec$StringCodec@728938a9, varint=com.datastax.driver.core.TypeCodec$BigIntegerCodec@5910e440, timeuuid=com.datastax.driver.core.TypeCodec$TimeUUIDCodec@6267c3bb, custom=com.datastax.driver.core.TypeCodec$BytesCodec@5010be6} {code} the primitiveCodecs should not depends on the static initialisers, it could instead create the instance itself. during the build I then get the following error {code} testInsertDbObjects(org.sfm.datastax.SettableDataMapperTest) Time elapsed: 0.089 sec <<< ERROR! java.lang.NullPointerException: null at com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:209) at com.datastax.driver.core.DefaultPreparedStatement.bind(DefaultPreparedStatement.java:103) at org.sfm.datastax.SettableDataMapperTest.checkObjectInserted(SettableDataMapperTest.java:45) {code} or {code} testMapSetUDT(org.sfm.datastax.DatastaxMapperCollectionTest) Time elapsed: 0.331 sec <<< ERROR! java.lang.NullPointerException: null at com.datastax.driver.core.DataType.deserialize(DataType.java:673) at com.datastax.driver.core.AbstractData.hashCode(AbstractData.java:457) at com.datastax.driver.core.UDTValue.hashCode(UDTValue.java:69) at java.util.HashMap.hash(HashMap.java:338) at java.util.HashMap.put(HashMap.java:611) at java.util.HashSet.add(HashSet.java:219) at com.datastax.driver.core.TypeCodec$SetCodec.deserialize(TypeCodec.java:1076) at com.datastax.driver.core.TypeCodec$SetCodec.deserialize(TypeCodec.java:1001) at com.datastax.driver.core.AbstractGettableByIndexData.getSet(AbstractGettableByIndexData.java:343) at com.datastax.driver.core.AbstractGettableData.getSet(AbstractGettableData.java:26) at org.sfm.datastax.impl.getter.DatastaxSetWithConverterGetter.get(DatastaxSetWithConverterGetter.java:24) at org.sfm.datastax.impl.getter.DatastaxSetWithConverterGetter.get(DatastaxSetWithConverterGetter.java:10) at org.sfm.map.impl.fieldmapper.FieldMapperImpl.mapTo(FieldMapperImpl.java:23) {code} see https://travis-ci.org/arnaudroger/SimpleFlatMapper/jobs/83902196
    via by Arnaud Roger,
    • java.lang.NullPointerException: null at com.datastax.driver.core.DataType.deserialize(DataType.java:673) at com.datastax.driver.core.AbstractData.hashCode(AbstractData.java:457) at com.datastax.driver.core.UDTValue.hashCode(UDTValue.java:69) at java.util.HashMap.hash(HashMap.java:338) at java.util.HashMap.put(HashMap.java:611) at java.util.HashSet.add(HashSet.java:219) at com.datastax.driver.core.TypeCodec$SetCodec.deserialize(TypeCodec.java:1076) at com.datastax.driver.core.TypeCodec$SetCodec.deserialize(TypeCodec.java:1001) at com.datastax.driver.core.AbstractGettableByIndexData.getSet(AbstractGettableByIndexData.java:343) at com.datastax.driver.core.AbstractGettableData.getSet(AbstractGettableData.java:26) at org.sfm.datastax.impl.getter.DatastaxSetWithConverterGetter.get(DatastaxSetWithConverterGetter.java:24) at org.sfm.datastax.impl.getter.DatastaxSetWithConverterGetter.get(DatastaxSetWithConverterGetter.java:10) at org.sfm.map.impl.fieldmapper.FieldMapperImpl.mapTo(FieldMapperImpl.java:23)
    No Bugmate found.