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

NullReference exception in ReqlExpr #55

Closed
oliverjanik opened this issue May 17, 2016 · 6 comments
Closed

NullReference exception in ReqlExpr #55

oliverjanik opened this issue May 17, 2016 · 6 comments
Labels

Comments

@oliverjanik
Copy link

You've got an override for == operator here:

    public static ReqlExpr operator ==(ReqlExpr a, ReqlExpr b)
    {
      return (ReqlExpr) a.eq((object) b);
    }

This throws when I do a comparison like this:

if (expr == null) ...

Got me very confused for a second. Can null be special cased here?

@bchavez
Copy link
Owner

bchavez commented May 17, 2016

Hey @oliverjanik , I think you need to use ReferenceEquals when comparing null with the AST ReqlExpr.

Could you provide more context with how you're using and why you're checking null?

Thanks,
Brian

@oliverjanik
Copy link
Author

Yeah that's what I ended up doing, but it confused the hell out of me for a while. Is it intended to be like that?

@bchavez
Copy link
Owner

bchavez commented May 20, 2016

@oliverjanik Yea, the operator overload for == is intended. This allows us to write queries like:

.Filter(g => g[nameof(Game.points)].Eq(9))
.Filter(g => g[nameof(Game.points)] == 9) //op overload

Fancy! 👍

Wiki docs for this are here: https://github.com/bchavez/RethinkDb.Driver/wiki/Extra-C%23-Driver-Features#implicit-conversion-operator-overload

@oliverjanik
Copy link
Author

g[nameof(Game.points)] is never null in these situations, would a null check break anything?

@bchavez
Copy link
Owner

bchavez commented May 24, 2016

Hey Oliver,

g[nameof(Game.points)] isn't null per se but I think the field in the JSON document could be null. The server would have the necessary information.

Consider what happens with:

(g => g[nameof(Game.points)] == 9)

This check doesn't happen on the client, it happens on the server. == 9 gets converted into ReQL: .Eq(9). Same would apply for null: == null -> .Eq(null).

🍷 🌴 _"Get drunk on the good life, I'll take you to paradise..."_

@oliverjanik
Copy link
Author

Alright then, I'm closing this issue.

On a sidenote: It feels like Rethink guys reinvented Expression trees in their Java driver.

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

No branches or pull requests

2 participants