Bug? java.lang.NullPointerException on Null value

Discussion in 'B4J Bugs & Wishlist' started by PatrikCavina, May 24, 2019.

  1. PatrikCavina

    PatrikCavina Active Member Licensed User

    This code causes an error:
    Code:
    If Null = "aa" Then
            
    Log("Ok")
        
    Else
            
    Log("No")
        
    End If
    But if i write the code in this way errors don't happen::
    Code:
    If "aa" = Null Then
            
    Log("Ok")
        
    Else
            
    Log("No")
        
    End If
    I don't think is a normal behavior
     
  2. sorex

    sorex Expert Licensed User

    I guess the logic is that NULL is non existing.

    You can't compare something that doesn't exist with a string.

    But you can compare a string with being nothing.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    This is the expected behavior. As part of the comparison a method is called on the left side object (for non-primitive types). This fails when the left side value is Null.
    There is a special case with explicit Nulls on the right side which changes the way the comparison is made (reference check).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice