title: How can I avoid null using lambda in this case?
body: <p>The following method you have seen returns all the information of the user in the database according to the phone number as follows.</p>
  <pre><code>{
    &quot;message&quot;: &quot;The operation was successful.&quot;,
    &quot;code&quot;: 200,
    &quot;fileDetailResponseDtos&quot;: [
      {
        &quot;phoneNumber&quot;: &quot;550000000&quot;,
        &quot;textMessage&quot;: &quot;Message1&quot;,
        &quot;createDateTime&quot;: &quot;2021-10-20T15:45:27.277&quot;,
        &quot;sender&quot;: &quot;Anar&quot;,
        &quot;status&quot;: 0,
        &quot;originatry&quot;: 0
      },
      {
        &quot;phoneNumber&quot;: &quot;550000000&quot;,
        &quot;textMessage&quot;: &quot;Message2&quot;,
        &quot;createDateTime&quot;: &quot;2021-10-20T15:45:27.277&quot;,
        &quot;sender&quot;: &quot;Anar&quot;,
        &quot;status&quot;: 0,
        &quot;originatry&quot;: 0
      },
      {
        &quot;phoneNumber&quot;: &quot;550000000&quot;,
        &quot;textMessage&quot;: &quot;Message3&quot;,
        &quot;createDateTime&quot;: &quot;2021-10-20T15:45:27.277&quot;,
        &quot;sender&quot;: &quot;Anar&quot;,
        &quot;status&quot;: 0,
        &quot;originatry&quot;: 0
      }
    ]
  }
  </code></pre>
  <p>However, when I perform an operation based on a phone number that is not in the database, it still returns the second part instead of this message.</p>
  <pre><code>{
    &quot;message&quot;: &quot;The operation was successful&quot;,
    &quot;code&quot;: 200,
    &quot;fileDetailResponseDtos&quot;: []
  }
  </code></pre>
  <p>But I want it to look like this in the output.</p>
  <pre><code>{
    &quot;message&quot;: &quot;Unfortunately, no information was found for this number.&quot;,
    &quot;code&quot;: 400,
  }
  </code></pre>
  <p>Yes I know it's not possible to return a list null. Here is the method I wrote in the dao layer.</p>
  <p>How can I output the message I want when I perform an invalid operation?</p>
  <pre><code>@Override
  public List&lt;FileDetail&gt; getByPhoneNumberCBVersion(String phoneNumber) {
      CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
      CriteriaQuery&lt;FileDetail&gt; generateQueryWithMethods = criteriaBuilder.createQuery(FileDetail.class);
      Root&lt;FileDetail&gt; starsFrom = generateQueryWithMethods.from(FileDetail.class);
      generateQueryWithMethods.select(starsFrom);
      generateQueryWithMethods.where(criteriaBuilder.equal(starsFrom.get(&quot;phoneNumber&quot;), phoneNumber));
      TypedQuery&lt;FileDetail&gt; query = entityManager.createQuery(generateQueryWithMethods);
      List&lt;FileDetail&gt; resultList = query.getResultList();
      return resultList;
  }
  </code></pre>