1. I'm using weld-se and setup with defaults
Weld weld = new Weld();
WeldContainer container = weld.initialize();
2. Write some Messageclasses for event passing and fire the event with containerevents
ApplicationStart start = new ApplicationStart(container);
container.event().fire(start);
3. while working with events I fire up a File Event (simple Bean Class with JPA Annotations)
4. A ManagerClass registrate the Event and Observes the File Event (Now the Problem)
public void onFile(@Observes File file)
{ ...}
5. the method is not static and contains a lambda (Java8)
5.1 if some file properties are null then the lambda is running into NPE
5.2 if properties are ok then all works
6. the is a switch in the method to check if case 5.1 or 5.2 happens and do not evaluate the lambda but this does not work!
if (file.getSha() != null)
{ ... LAMBDA here and STREAM API ....}
else
{ ... some exit code .... }
7. the error is befor the onFile observer is executed the stream API is evaluated from WELD and the NPE occurs. the code block is not used by the method.
Working CODE is now:
if (file.getSha() != null) {
// insert oder update
// gib es bereits ein file?
TypedQuery<File> qf = manager
.createQuery(
"SELECT f FROM File f WHERE f.sha = :sha AND f.provider = :provider",
File.class);
qf.setParameter("sha", file.getSha());
qf.setParameter("provider", file.getProvider());
List<File> files = qf.getResultList();
if (files != null && !files.isEmpty()) {
// was macht weld hier? NPE
String pathMatch = file.getFilePath();
long test = 0;
for (File f : files) {
if (f.getFilePath().equals(pathMatch))
{
test++;
}
}
and i can't find the error for this snipped
long test = files.stream().filter(f -> f.getFilePath().equals(file.getFilePath())).count();
if this file.getPath() is null it wound work, but this is in case not null (getSHA() and getFilePath() are both null or both not null)
i've fixed my version of code an haven't tested on an new version of WELD
can someone test Java8 and stream API with weld.
or explain why WELD execute onFile as static method?