glassfish
  1. glassfish
  2. GLASSFISH-16591

CriteriaBuilder.or causes NullPointerException even though nothing is null

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: v3.0.1, 3.1
    • Fix Version/s: future release
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Linux nexus 2.6.32-5-amd64 #1 SMP Mon Mar 7 21:35:22 UTC 2011 x86_64
      glassfish 3.1 and 3.0.1
      Java(TM) SE Runtime Environment (build 1.6.0_25-b06) and 1.6.0_24

      Description

      inside a stateless session bean the following method throws a NullPointerException in line 136:
      public List<IdkoBasicPerson> abgelaufeneImpfungen(@WebParam(name = "Datum") final Date datum) {
      CriteriaBuilder cb = em.getCriteriaBuilder();
      CriteriaQuery<IdkoBasicPerson> cq = cb.createQuery(IdkoBasicPerson.class);
      Root<IdkoBasicPerson> root = cq.from(IdkoBasicPerson.class);
      Predicate impf = cb.disjunction();
      List<String> vaccinations = this.impfungen();
      for (String tmp : this.impfungen()) {
      try {
      if (impf != null && root.<Date>get(tmp).isNull() != null && cb.lessThan(root.<Date>get(tmp), cb.currentDate()) != null) System.err.println("\nnothing is null\n");
      } catch(NullPointerException e) {
      System.err.println("\nsomething was null\n");
      }
      if (datum == null)

      { impf = cb.or(impf, root.<Date>get(tmp).isNull(), cb.lessThan(root.<Date>get(tmp), cb.currentDate()))); //line 136 }

      else

      { impf = cb.or(impf, root.get(tmp).isNull(), cb.lessThan(root.<Date>get(tmp), datum))); }

      }
      cq.where(impf.not()).orderBy(cb.asc(root.get("lastname")), cb.asc(root.get("firstname")));
      cq.select(root);
      return em.createQuery(cq).getResultList();
      }

      When or(Predicate ...) is replaced with and(Predicate ...) in line 136 no Exception is thrown - but of course query logic returns unwanted result list:
      impf = cb.and(impf, root.<Date>get(tmp).isNull(), cb.lessThan(root.<Date>get(tmp), cb.currentDate())));

      1. server.log
        202 kB
        deathtooracle

        Activity

        deathtooracle created issue -
        Nazrul made changes -
        Field Original Value New Value
        Assignee Nazrul [ ai109478 ] marina vatkina [ mvatkina ]
        Component/s ejb_container [ 10596 ]
        marina vatkina made changes -
        Assignee marina vatkina [ mvatkina ] Mitesh Meswani [ mm110999 ]
        Component/s entity-persistence [ 10624 ]
        Component/s ejb_container [ 10596 ]
        Mitesh Meswani made changes -
        Tags 3_1_1-scrubbed
        Mitesh Meswani made changes -
        Tags 3_1_1-scrubbed 3_1_1-scrubbed 3_1_2-exclude
        Mitesh Meswani made changes -
        Fix Version/s future release [ 11148 ]

          People

          • Assignee:
            Mitesh Meswani
            Reporter:
            deathtooracle
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: