Skip to content

MINOR: improve Streams checkstyle and code cleanup#5954

Merged
mjsax merged 6 commits intoapache:trunkfrom
mjsax:minor-checkstyle-code-cleanup
Dec 11, 2018
Merged

MINOR: improve Streams checkstyle and code cleanup#5954
mjsax merged 6 commits intoapache:trunkfrom
mjsax:minor-checkstyle-code-cleanup

Conversation

@mjsax
Copy link
Copy Markdown
Member

@mjsax mjsax commented Nov 27, 2018

While fixing the code to meet the new checkstyle rule, I updated all touched classed for Java8 and removed other warnings.

@mjsax mjsax added the streams label Nov 27, 2018
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be controversial. I change it, to reuse the return type of ApiUtils.validateMillisecondDuration. (Similar in other XxxWindows classes).

Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine to me.

@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Nov 27, 2018

Call for review @guozhangwang @bbejeck @vvcephei

Copy link
Copy Markdown
Contributor

@guozhangwang guozhangwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to merge after addressed / replied the comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine to me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? I'm concerned someone out there in the wild may have extended this class for their customized needs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a warning. Note that Stores has only static methods, thus it does not make sense to inherit from it. I can still revert it. Don't feel strong about it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? If they are retained as comments just for context information I'd suggest use /**/ as a nit comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer keep it as general so that the same function can be reused in the future potentially rather than explicitly restrict is usage scope.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think validateXXX method shouldn't return value.
That's why I made it void in the first place.

Maybe we need a more convenient name for it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I made it void in the first place.

It's not void -- and this PR does not change it. I think it makes sense to let it return for this case though. To validate the given Duration, we need to call #toMillis() within validateMillisecondDuration() and thus, there is no reason to call it twice (even if this is not on the critical code path).

We can still rename it. Maybe something like, getMillisecondDurationOrFailIfInvalid ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we call deprecated method close(DEFAULT_CLOSE_TIMEOUT, TimeUnit.SECONDS); -- this method will stay though, ie, we will make it private when we "remove" it from public API and than we can remove this annotation, too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why are we adding calls to deprecated code?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't add calls -- this call was always there and we need to keep it for backward compatibility until we remove those methods (by making them private).

Comment thread checkstyle/checkstyle.xml Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a real shame that we have this inconsistency. And it only makes the code worse, this PR being a good example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to enable this check style for the whole code base (similar to final requirement). But not sure if we get some push back -- thus, it seems to be better to introduce those things step by step?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was suggesting the opposite. What's the justification for this rule? At least for final, there is the mutability argument. The truth is that Java is becoming a more modern language and redundant verbosity is being eliminated (an extreme example that has been proposed http://openjdk.java.net/jeps/8209434). Requiring braces in every situation perhaps made sense for the old Java. :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me personally, it's readability question -- I think, it improves readability.

Also, this rule only required braces for if/else and loop-blocks. Not for every situation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what other situation is there where braces are optional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch-case statement

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor question, otherwise LGTM modulo other comments

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just remove these?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong opinion -- might be nice to keep for documentation (ie, the benchmark describes those fields, but we just don't use them?) Thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Maybe we could add a couple of words in the comment?
But it's not a big deal, so it could just stay as is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijuma Removed the SuppressWarning annotation and rewrote the code. Also have a PR for 2.1 branch: #5963 for this fix.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We translate old default of zero to Long.MAX_VALUE within deprecated close(final long timeout, final TimeUnit timeUnit) -- we can call private close() directly instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks better.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these IntelliJ warnings?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Comment thread checkstyle/checkstyle.xml Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what other situation is there where braces are optional?

@mjsax mjsax force-pushed the minor-checkstyle-code-cleanup branch from c397804 to 0040a8b Compare December 6, 2018 22:33
@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Dec 6, 2018

Rebased this. Also added some JavaDoc fixes.

@ijuma Do you still have objections about the enforced use of braces in streams module?

@ijuma
Copy link
Copy Markdown
Member

ijuma commented Dec 7, 2018

@mjsax I'm not going to block it, but this doesn't make sense to me. The Apache Kafka project is a single project and it should use the same code style across the board for a given programming language, in my opinion.

Imagine if we had a different code style per module: clients, connect, streams, tools. Do you think that would work OK? Why is streams special?

@guozhangwang
Copy link
Copy Markdown
Contributor

I think I'd agree with @ijuma 's concern that, it is not for arguing if which coding style should be preferred, but about maintaining the coding style consistency of modules under AK repo.

Personally I also prefer unambiguous syntax and I see the merits of, for example, posing strict reviews on proper markups / javadocs on public APIs etc in practice, but enforcing checkstyle rules only for Streams may have potential side-effect to the integral community in long run (I've seen other projects leading to this direction that resulted in separated sub-projects). So I'd suggest we remove the checkstyle rule while merging this PR, and moving forward we would still encourage reviewers to use their own best judgement to determine if some places would be vulnerable to future bugs or really bad for readability that worth a nitpick comment.

@mjsax mjsax merged commit 046b008 into apache:trunk Dec 11, 2018
@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Dec 11, 2018

Removed checkstyle rule. Merged all other cleanups. Thanks for your comments and the discussion about it!

Merged to trunk

@mjsax mjsax deleted the minor-checkstyle-code-cleanup branch December 11, 2018 09:55
pengxiaolong pushed a commit to pengxiaolong/kafka that referenced this pull request Jun 14, 2019
Reviewers: Guozhang Wang <guozhang@confluent.io>, Nikolay Izhikov <nIzhikov@gmail.com>, Ismael Juma <ismael@confluent.io>, Bill Bejeck <bill@confluent.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants