title: Firestore: Checking NotNull in a transaction and impede from calling the OnSuccessful callback
body: <p>In the function <code>apply</code> of my Firestore transaction, I've written <code>DocumentSnapshot snapshot = transaction.get(xyz);</code> so that I get a reference to the document snapshot. I want to read one of it fields, but before I should check this field is contained (<code>if(snapshot.contains("the field"))</code>) and if it's not null (<code>if(snapshot.getDouble("the field")) != null</code>). <strong>Otherwise, I show an error message.</strong></p>
  
  <p>Also, I have written a validation message in the callback <code>OnSuccess</code>, which is triggered if the transaction could run (<em>i.e.:</em> if <code>apply</code> returned).</p>
  
  <p><strong>So both the error message and the validation message will be shown.</strong></p>
  
  <p>Below is an example:</p>
  
  <pre><code>FirebaseFirestore.getInstance().runTransaction(new Transaction.Function&lt;Void&gt;() {
                                      @Override
                                      public Void apply(@NonNull Transaction transaction) throws FirebaseFirestoreException {
                                          DocumentSnapshot snapshot = transaction.get(object_to_update);
                                          if(snapshot.contains("amount") &amp;&amp; snapshot.getDouble("amount") != null) {
                                              double new_amount = snapshot.getDouble("amount") + seek_bar_value;
                                              transaction.update(object_to_update, "amount", new_amount);
  
                                          } else {
  
                                              Toast.makeText(context, "Error: Unable to find a required field to process the transaction correctly.", Toast.LENGTH_SHORT).show();
                                          }
                                          return null;
                                      }
                                  }).addOnFailureListener(new OnFailureListener() {
                                      @Override
                                      public void onFailure(@NonNull Exception e) {
                                          Toast.makeText(context, "Error: Unable to update the data.", Toast.LENGTH_SHORT).show();
                                      }
                                  }).addOnSuccessListener(new OnSuccessListener&lt;Void&gt;() {
                                      @Override
                                      public void onSuccess(Void aVoid) {
                                          Toast.makeText(context, "Congratulations, the data has been updated.", Toast.LENGTH_SHORT).show();
  </code></pre>
  
  <p>So the problem is that the message "Error: Unable to find a required field to process the transaction correctly." and {the message "Congratulations, the data has been updated." or "Error: Unable to update the data."} will be both shown.</p>
  
  <p><strong>How could I fix this problem?</strong> Perhaps I could use a boolean in the callback <code>OnSuccess</code> to know if the <code>apply</code>'s checks Contains and NotNull didn't show the error message, so that <code>OnSuccess</code> can show the validaton message, for example. But is there another way to solve the problem?</p>