Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when Deactivating type mapping #210

Closed
Joalien opened this issue Dec 7, 2020 · 6 comments
Closed

NullPointerException when Deactivating type mapping #210

Joalien opened this issue Dec 7, 2020 · 6 comments
Labels

Comments

@Joalien
Copy link

Joalien commented Dec 7, 2020

To deactivate the type mapping, the documentation advises to set typeKey to null

As explained in the documentation

deactivating type mapping may lead to exceptions when reading the entities from the DB.

In the method com.arangodb.springframework.core.convert.DefaultArangoTypeMapper.DefaultTypeAliasAccessor#readAliasFrom, the call source.get(this.typeKey); throws a NullPointerException when this.typeKey is null. I suggest to add a non-null check before

before

if (source.isObject()) {
    final VPackSlice typeKey = source.get(this.typeKey);
    return Alias.ofNullable(typeKey.isString() ? typeKey.getAsString() : null);
}

after

if (source.isObject()) {
    if (this.typeKey == null) return Alias.NONE;
    final VPackSlice typeKey = source.get(this.typeKey);
    return Alias.ofNullable(typeKey.isString() ? typeKey.getAsString() : null);
}

Here is the linked pull request

@rashtao
Copy link
Collaborator

rashtao commented Dec 11, 2020

VPackSlice.get(String) does not require a non-null argument. In such case it should return a VPackSlice.NONE_SLICE.
Can you please provide the stacktrace of the exception? Or can you include a test in your PR?

@Joalien
Copy link
Author

Joalien commented Dec 14, 2020

Here is my stacktrace :

java.lang.NullPointerException
	at java.lang.String.compareTo(String.java:1155)
	at com.arangodb.velocypack.VPackSlice.compareString(VPackSlice.java:757)
	at com.arangodb.velocypack.VPackSlice.searchObjectKeyBinary(VPackSlice.java:585)
	at com.arangodb.velocypack.VPackSlice.get(VPackSlice.java:524)
	at com.arangodb.springframework.core.convert.DefaultArangoTypeMapper$DefaultTypeAliasAccessor.readAliasFrom(DefaultArangoTypeMapper.java:183)
	at com.arangodb.springframework.core.convert.DefaultArangoTypeMapper.readType(DefaultArangoTypeMapper.java:97)
	at com.arangodb.springframework.core.convert.DefaultArangoTypeMapper.readType(DefaultArangoTypeMapper.java:105)
	at com.arangodb.springframework.core.convert.DefaultArangoConverter.readInternal(DefaultArangoConverter.java:141)
	at com.arangodb.springframework.core.convert.DefaultArangoConverter.read(DefaultArangoConverter.java:129)
	at com.arangodb.springframework.core.convert.DefaultArangoConverter.read(DefaultArangoConverter.java:88)
	at com.arangodb.springframework.core.template.ArangoExtCursorIterator.deserialize(ArangoExtCursorIterator.java:60)
	at com.arangodb.internal.cursor.ArangoCursorIterator.next(ArangoCursorIterator.java:75)
	at com.arangodb.internal.cursor.ArangoCursorImpl.next(ArangoCursorImpl.java:112)
	at com.arangodb.springframework.repository.query.ArangoResultConverter.getNext(ArangoResultConverter.java:251)
	at com.arangodb.springframework.repository.query.ArangoResultConverter.convertResult(ArangoResultConverter.java:120)
	at com.arangodb.springframework.repository.query.AbstractArangoQuery.convertResult(AbstractArangoQuery.java:189)
	at com.arangodb.springframework.repository.query.AbstractArangoQuery.execute(AbstractArangoQuery.java:82)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy97.findUserByUsername(Unknown Source)
        ...

@rashtao
Copy link
Collaborator

rashtao commented Dec 14, 2020

The stacktrace does not seem to be related to com.arangodb:velocypack:2.4.1. Can you please check which version of com.arangodb:velocypack you are using?

@Joalien
Copy link
Author

Joalien commented Dec 14, 2020

Indeed, I was using com.arangodb:velocypack:1.4.1.
I updated velocypack version and here is the stackstrace :

java.lang.NullPointerException
	at com.arangodb.velocypack.VPackSlice.searchObjectKeyBinary(VPackSlice.java:698)
	at com.arangodb.velocypack.VPackSlice.get(VPackSlice.java:649)
	at com.arangodb.springframework.core.convert.DefaultArangoTypeMapper$DefaultTypeAliasAccessor.readAliasFrom(DefaultArangoTypeMapper.java:183)
	at com.arangodb.springframework.core.convert.DefaultArangoTypeMapper.readType(DefaultArangoTypeMapper.java:97)
	at com.arangodb.springframework.core.convert.DefaultArangoTypeMapper.readType(DefaultArangoTypeMapper.java:105)
	at com.arangodb.springframework.core.convert.DefaultArangoConverter.readInternal(DefaultArangoConverter.java:126)
	at com.arangodb.springframework.core.convert.DefaultArangoConverter.read(DefaultArangoConverter.java:114)
	at com.arangodb.springframework.core.convert.DefaultArangoConverter.read(DefaultArangoConverter.java:73)
	at com.arangodb.springframework.core.template.ArangoExtCursorIterator.deserialize(ArangoExtCursorIterator.java:60)
	at com.arangodb.internal.cursor.ArangoCursorIterator.next(ArangoCursorIterator.java:74)
	at com.arangodb.internal.cursor.ArangoCursorImpl.next(ArangoCursorImpl.java:111)
	at com.arangodb.springframework.repository.query.ArangoResultConverter.getNext(ArangoResultConverter.java:251)
	at com.arangodb.springframework.repository.query.ArangoResultConverter.convertResult(ArangoResultConverter.java:120)
	at com.arangodb.springframework.repository.query.AbstractArangoQuery.convertResult(AbstractArangoQuery.java:189)
	at com.arangodb.springframework.repository.query.AbstractArangoQuery.execute(AbstractArangoQuery.java:82)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy97.findUserByUsername(Unknown Source)

@rashtao
Copy link
Collaborator

rashtao commented Dec 15, 2020

Thanks for reporting, I see the problem now!
VPackSlice.get(null) returns from some if-else branches VPackSlice.NONE_SLICE and from others throws NPE.
I fixed here, a patch release will follow soon.

@rashtao rashtao added bug and removed question labels Dec 21, 2020
@rashtao
Copy link
Collaborator

rashtao commented Dec 21, 2020

@rashtao rashtao closed this as completed Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants