lundi 30 mars 2015

Spring Boot odd behavior with Java8

I started a project on SpringBoot to performs some tests.


What was interesting is the following.


I have a class which initializes some collections during construction(to avoid NPE).


So far so good if i test using JUnit but on SpringBoot i had to move the collection initialization outside the constructor...


On class throwing null pointer exception.



public TuneArtist()
{
records = new HashSet<TuneRecord>();
credits = new HashSet<TuneCredit>();
releases = new HashSet<TuneRelease>();
}


The result code...



tuneArtist.setReleases(new HashSet<TuneRelease>());
info.getReleases().forEach(p -> tuneArtist.getReleases().
add(new TuneRelease(p.getId() , p.getName())));

tuneArtist.setCredits(new HashSet<TuneCredit>());
info.getCredits().forEach(p->tuneArtist.getCredits()
.add(new TuneCredit(p.getId() , p.getCreditName())));

Aucun commentaire:

Enregistrer un commentaire