X Tutup
Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: paulmillar/JSON-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: paulmillar/JSON-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fix/no-null-on-toString
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Sep 28, 2022

  1. do not return 'null' for toString

    Motivation:
    
    `null` is not a valid return value for Object#toString; for example, see:
    
    https://stackoverflow.com/questions/32378264/when-we-override-the-tostring-method-we-should-always-return-a-string-represen
    
    Additionally, catching Exception means that any RuntimeException (which
    is likely a bug in the underlying code) will be supressed, making it
    harder to figure out what is going wrong.
    
    Modification:
    
    The JSONObject#toString contract requires toString to return valid JSON.
    
    The code could return a valid JSON by returning a textural description
    of the JSONException as a quoted string; however, this would not make it
    clear than an error has occurred, and would likely be incompatible with
    the expected structure of the JSON (the schema).
    
    As JSONException is a RuntimeException, the code simply allow it to
    propagate.
    
    Result:
    
    JSONObject#toString no longer returns `null` under exceptional
    circumstances.
    paulmillar committed Sep 28, 2022
    Configuration menu
    Copy the full SHA
    1f60d9b View commit details
    Browse the repository at this point in the history
Loading
X Tutup