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

Methods that return NULL are flagged as @NonNull which annoys Kotlin #220

Closed
MKevin3 opened this issue Aug 3, 2020 · 6 comments
Closed

Comments

@MKevin3
Copy link

MKevin3 commented Aug 3, 2020

    @NonNull
    public final BarcodeResult getBarcodeResult() {
        long var1;
        return (var1 = barcodeResultNativeGet(this.getNativeContext())) != 0L ? new BarcodeResult(var1, this) : null;
    }

This method is flagged as @nonnull but you can easily tell it returns a null making it not friendly to Kotlin. The code could use an update to make it more Kotlin friendly

@matvidako
Copy link
Contributor

Hi,

thanks for reporting this, we'll update it in the next release.

@mikeberlin
Copy link

Awesome, thank you! Really appreciate the quick reply. Two follow up questions:

  1. There are several methods marked @nonnull but return null (not just the one instance above), will all of those be addressed in the next release? Hopefully so and not just this single method.

  2. When is the next release scheduled for?

@matvidako
Copy link
Contributor

Hi,

  1. we've found and fixed couple of similar cases in various recognizer classes. Have you seen the same issue in other classes?
  2. 5.7 is scheduled to be released in 2 weeks.

@MKevin3
Copy link
Author

MKevin3 commented Aug 17, 2020

I see you changed this in 5.7 to not return NULL but to throw an exception instead. Still leaves me with a try / catch block instead of a null check. Is this the pattern I can expect to find in the rest of the library?

@matvidako
Copy link
Contributor

We're deliberately throwing unchecked exception because we don't want you to try and catch it.
The case when we throw an exception can only happen if there is a serious bug in our code (results would be completely useless) so rather than hiding it by returning null, we're throwing an exception.

In other places in our SDK, we have something similar, throwing IllegalArgumentsException if you pass in unexpected arguments to our methods.
Again, the goal is to expose bugs (in this case in your code), rather than hiding the bug by defaulting to safe values.

@anjapenic
Copy link

Hi @MKevin3,

Since this issue is inactive, we're closing it. If you need any further assistance feel free to open a new issue or contact us at support@microblink.com.

Regards,
Anja

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

4 participants