question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated EntityViewImpl constructor will throw NPE for additional @Mapping collection fields

See original GitHub issue

Description

Generated CatWithKittenViewImpl constructor will throw NullPointerExceptions for additional @Mapping collection fields. See the following scenario:

public interface CatWithKittenView extends CatIdView {
	@Mapping("kittens[gender=com.example.Gender.MALE].owner")
	Collection<PersonIdView> getMaleKittenOwners();
}

The generated CatWithKittenViewImpl constructor:

public CatWithKittenViewImpl(        Long id) {
    this.$$_kind = (byte) 1;
    this.maleKittenOweners = (Collection<PersonIdView>) (java.util.Collection<?>) CatWithKittenView_.maleKittenOwners.attr().getCollectionInstantiator().createCollection(0);
    this.id = id;
}

In this case CatWithKittenView_.maleKittenOwners will throw the NPE since there is no maleKittenOwners field mapped in the enitiy.

Environment

Version: 1.6.0 JPA-Provider: 5.4 DBMS: MariaDB Application Server: Tomcat (Spring Boot)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
beikovcommented, May 15, 2021

Can you please confirm if enabling the scanning resolves your issue?

0reactions
beikovcommented, Jun 15, 2021

Thanks for confirming!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazebit - Bountysource
Generated CatWithKittenViewImpl constructor will throw NullPointerExceptions for additional @Mapping collection fields. See the following scenario:
Read more >
java - What is a NullPointerException, and how do I fix it?
Applications should throw instances of this class to indicate other illegal uses of the null object. It is also the case that if...
Read more >
Builder set methods null friendly · Issue #1451 - GitHub
When we are mapping a class to another, usually we end up with something like this: ... Builder will thrown a NullPointerException ....
Read more >
How to deal with NullPointerException in Java with Examples
NullPointerException has outlined scenario when it could occur: 1) When you call the instance method on a null object. you won't get a...
Read more >
Java NullPointerException - Detect, Fix, and Best Practices
When we run the above program, it throws the following NullPointerException error message. Exception in thread "main" java.lang.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found