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

ParseException message is null #38

Closed
jsimomaa opened this issue May 23, 2017 · 1 comment
Closed

ParseException message is null #38

jsimomaa opened this issue May 23, 2017 · 1 comment

Comments

@jsimomaa
Copy link

In some cases the detailMessage field is null for ParseException (and inheriting exceptions) resulting in non-descriptive logging with SLF4J and Logback.

I have the following code sample:

    private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) {
        try {
            Version.valueOf("v0.0.1");
        } catch (Exception e) {
            LOGGER.error("Could not parse version", e);
        }
    }

I know that the leading v is the cause for this exception. However, the code above produces the following output:

15:59:12.485 [main] ERROR Main - Could not parse version
com.github.zafarkhaja.semver.UnexpectedCharacterException: null
    at com.github.zafarkhaja.semver.VersionParser.consumeNextCharacter(VersionParser.java:516)
    at com.github.zafarkhaja.semver.VersionParser.digits(VersionParser.java:448)
    at com.github.zafarkhaja.semver.VersionParser.numericIdentifier(VersionParser.java:408)
    at com.github.zafarkhaja.semver.VersionParser.parseVersionCore(VersionParser.java:285)
    at com.github.zafarkhaja.semver.VersionParser.parseValidSemVer(VersionParser.java:255)
    at com.github.zafarkhaja.semver.VersionParser.parseValidSemVer(VersionParser.java:195)
    at com.github.zafarkhaja.semver.Version.valueOf(Version.java:265)
    at Main.main(Main.java:10)

which is not very descriptive.

I think this could be fixed quite simply with the following addition to ParseException:

    @Override
    public String getMessage() {
        if (super.getMessage() != null)
            return super.getMessage();
        return toString();
    }
@zafarkhaja
Copy link
Owner

Hello Jani! Sorry for the delay and thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants