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

Missing flags getter added #10000

Merged
merged 3 commits into from
Jul 15, 2023
Merged

Missing flags getter added #10000

merged 3 commits into from
Jul 15, 2023

Conversation

jpstotz
Copy link
Contributor

@jpstotz jpstotz commented Jun 30, 2023

The HeaderParser class is pretty handy when using org.eclipse.jetty.http2:http2-common as a library in other projects. Unfortunately it misses a getter to retrieve the flags and there are scenarios where you don't want to call hasFlag for every possible flag...

Signed-off-by: Jan Peter Stotz <jpstotz@gmx.de>
@sbordet
Copy link
Contributor

sbordet commented Jun 30, 2023

I'm not sure I understand in what scenario would the getter help?

You would have to get the int and then & it with every possible flag?

You typically don't need this because in the right places you look only for certain flags.
For example you don't look for Flags.END_STREAM if you're dealing with SETTINGS frames, etc.

@jpstotz
Copy link
Contributor Author

jpstotz commented Jun 30, 2023

@sbordet I need to have access to the raw flags value. At the moment I have to use reflection to do so just to get it work.
May be there are implementations which use non-official flags or the standard has changed or something else is different.
In the end it is way more safe to have the raw value instead of checking each possible flag.

Therefore having a getter in place is IMHO always a good idea. I don't see a point here why HeaderParser should hide the flags field. There is no advantage or requirement to hide it.

@sbordet
Copy link
Contributor

sbordet commented Jun 30, 2023

I need to have access to the raw flags value.

Why?

There is no advantage or requirement to hide it.

There is no advantage to expose it that you have articulated, besides "I have to access it".

The flags are used as a bitmap, so it is very easy to get confused and write code such as getFlags() == Flags.END_STREAM, which is wrong.
That's why it is hidden.

@jpstotz
Copy link
Contributor Author

jpstotz commented Jun 30, 2023

@sbordet For example I want to print the flags value in it's original form.

Just hiding a field because developers exists who does not understand how bitwise flags work is IMHO a bad decision.

In my opinion a better way to prevent an API from being used in a wrong way is by adding a detailed description.
Would you finally agree to add a getter if it would contain a JavaDoc comment?

@gregw
Copy link
Contributor

gregw commented Jul 3, 2023

@sbordet The information is already available via hasFlag, so the flags value can always be recovered with something like

   return
     (p.hasFlag(0x01) ? 0x01 : 0) |
     (p.hasFlag(0x02) ? 0x02 : 0) |
     (p.hasFlag(0x04) ? 0x04 : 0) |
     (p.hasFlag(0x08) ? 0x08 : 0) |
     (p.hasFlag(0x80) ? 0x10 : 0) |
     (p.hasFlag(0x80) ? 0x20 : 0) |
     (p.hasFlag(0x80) ? 0x40 : 0) |
     (p.hasFlag(0x80) ? 0x80 : 0) ;

So we are not hiding the data and if there is a user that wants them collectively, then I see no harm providing that.

@jpstotz javadoc would be helpful, specially as it could have a reference to the Flags class

@gregw
Copy link
Contributor

gregw commented Jul 7, 2023

@sbordet nudge, I'm not seeing the issue with a simple getter like this?

@sbordet sbordet merged commit e90bccb into jetty:jetty-10.0.x Jul 15, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

3 participants