Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optXXX() should return default value instead of throwing a RuntimeException #78

Open
h-cheon opened this issue Jun 14, 2023 · 0 comments

Comments

@h-cheon
Copy link

h-cheon commented Jun 14, 2023

For example, the description of optBoolean is

     * Get an optional boolean associated with a key.
     * It returns the defaultValue if there is no such key, or if it is not
     * a Boolean or the String "true" or "false" (case insensitive).

But actually it returns the defaultValue only when the key is not in the json, and throws a RuntimeException in other cases.

    public boolean optBoolean(String key, boolean defaultValue) {
        Object o = opt(key);
        if (o == null) {
        	return defaultValue;
        } else {
        	try {
        	    return doGetBoolean(key, o);
        	} catch (JSONException ex) {
        		throw new RuntimeException(ex);
        	}
        }
    }
h-cheon added a commit to h-cheon/jettison that referenced this issue Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant