Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2030

Weld error if using lambda/streams and events

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.2.16.Final
    • 2.2.14.Final
    • None
    • None
    • Hide

      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?

      Show
      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?

      Error is an NPE somewhere in weld core.

      I'll provide some Code just for lookup, this will not work and can't be started
      Main start WELD and the DatabseManager waits for incoming JMS messages.
      JMS Message is repacked and dispatched as event to FileManager. (at this POINT if using streams an NPE occurs)

        1. cdi-se-app1.zip
          4 kB
        2. DatabaseManager.java
          4 kB
        3. File.java
          5 kB
        4. FileManager.java
          7 kB
        5. Main.java
          1 kB

              Unassigned Unassigned
              jenskapitza Jens Kapitza (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: