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

Npe while gettings shadows #560

Closed
fsoylemez opened this issue Jun 29, 2017 · 11 comments
Closed

Npe while gettings shadows #560

fsoylemez opened this issue Jun 29, 2017 · 11 comments

Comments

@fsoylemez
Copy link

Hello,
I am getting NullPointerException while trying to get shadows of an entity.
I build the query with instanceId and with parameter shadowscopedeep.And i have 'to' parameter set,as i want the latest shadow (if exist) till the provided time.(My javers version is 3.3.2)

This is how i call it;
` DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

    E model = findById(id);
    QueryBuilder queryBuilder = QueryBuilder.byInstanceId(id, model.dtoClass()).withShadowScopeDeep();
    if(from!=null && !from.isEmpty()){
        queryBuilder.from(LocalDateTime.parse(from,formatter));
    }
    if(to!=null && !to.isEmpty()){
        queryBuilder.to(LocalDateTime.parse(to,formatter));
    }
    List<Shadow<E>> shadows = javers.findShadows(queryBuilder.build());`

And here is the stacktrace:
Caused by: java.lang.NullPointerException at org.javers.repository.jql.ShadowQueryRunner$CommitTable.lambda$loadFullCommits$78(ShadowQueryRunner.java:94) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) at org.javers.repository.jql.ShadowQueryRunner$CommitTable.loadFullCommits(ShadowQueryRunner.java:94) at org.javers.repository.jql.ShadowQueryRunner.queryForShadows(ShadowQueryRunner.java:36) at org.javers.repository.jql.QueryRunner.queryForShadows(QueryRunner.java:40) at org.javers.core.JaversCore.findShadows(JaversCore.java:143) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498)

@bartoszwalacik
Copy link
Member

Okay, could you please post the full code needed to reproduce this NPE?

@fsoylemez
Copy link
Author

i am guessing it is about setting from/to fields.Because if i comment out setting from/to,no exception is thrown.i will try to prepare test case to reproduce the situation.

@fsoylemez
Copy link
Author

the problem is commitsMap is empty while trying to append CommitEntry like;
((ShadowQueryRunner.CommitEntry)this.commitsMap.get(s.getCommitMetadata())).append(s);

@bartoszwalacik
Copy link
Member

Okay, waiting for the test case

@fsoylemez
Copy link
Author

fsoylemez commented Jun 30, 2017

public List<Shadow> queryForShadows(JqlQuery query, List<CdoSnapshot> coreSnapshots) {
       ShadowQueryRunner.CommitTable commitTable = new ShadowQueryRunner.CommitTable(coreSnapshots);
       if(query.getShadowScope() == ShadowScope.COMMIT_DEPTH) {
           commitTable.loadFullCommits();
       }

       return (List)commitTable.rootsForQuery(query).stream().map((r) -> {
           return this.shadowFactory.createShadow(r.root, r.context, (cm, targetId) -> {
               return commitTable.findLatestTo(cm, targetId);
           });
       }).collect(Collectors.toList());
   }

Hello Bartos,
I think the above method should return empty list at the very beginning of the method if coreSnapshots list is empty.Since we have no match,there is no need to go on.Dont you agree?

@bartoszwalacik
Copy link
Member

Use three backticks to format code :)

@fsoylemez
Copy link
Author

Hello ,
any update on the issue?

@bartoszwalacik
Copy link
Member

We cant start without a failing test case, please push it to your fork of javers repository

@fsoylemez
Copy link
Author

Okay,i may sound noob,but i pulled your master branch and prepared a test case.How do i send merge request?

fsoylemez pushed a commit to fsoylemez/javers that referenced this issue Jul 3, 2017
@bartoszwalacik
Copy link
Member

ok, now I can reproduce it on my machine, we will fix the bug

@bartoszwalacik
Copy link
Member

fix released in 3.3.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants