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

KAFKA-4796: Fix some findbugs warnings in Kafka Java client #2593

Closed
wants to merge 4 commits into from

Conversation

cmccabe
Copy link
Contributor

@cmccabe cmccabe commented Feb 24, 2017

No description provided.

@asfbot
Copy link

asfbot commented Feb 24, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1829/
Test FAILed (JDK 8 and Scala 2.11).

@asfbot
Copy link

asfbot commented Feb 24, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1827/
Test FAILed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented Feb 24, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1826/
Test FAILed (JDK 7 and Scala 2.10).

Copy link
Contributor

@ijuma ijuma left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, good improvement overall, left a few comments.

@@ -68,7 +68,7 @@
*/
public class ConfigDef {

public static final Object NO_DEFAULT_VALUE = new String("");
public static final Object NO_DEFAULT_VALUE = "";
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is not right. We are using this field as a sentinel and that's why there is the new String there. We could perhaps just use new Object as this seems to confuse findBugs and people (it's not the first time that someone thought this was a bug).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the explanation. Let me add a comment explaining why the new is there.

if (thisField == null)
return otherField == null;
else
return thisField.equals(otherField);
Copy link
Contributor

Choose a reason for hiding this comment

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

The ternary operator is often used in such cases, any reason not to do that here?

result = thisField == null ? otherField == null : thisFied.equals(otherField);

Copy link
Contributor Author

@cmccabe cmccabe Feb 28, 2017

Choose a reason for hiding this comment

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

Ternary sounds good here

@@ -139,7 +140,7 @@ private static String toString(final byte[] b, int off, int len) {
*/
public final static Comparator<byte[]> BYTES_LEXICO_COMPARATOR = new LexicographicByteArrayComparator();

private interface ByteArrayComparator extends Comparator<byte[]> {
private interface ByteArrayComparator extends Comparator<byte[]>, Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

We normally don't make things Serializable unless there's a good reason to do it. Is there a good reason?

Copy link
Contributor Author

@cmccabe cmccabe Feb 28, 2017

Choose a reason for hiding this comment

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

The JavaDoc for java.util.Comparator says that:

Note: It is generally a good idea for comparators to also implement java.io.Serializable, as they may be used as ordering methods in serializable data structures (like TreeSet, TreeMap). In order for the data structure to serialize successfully, the comparator (if provided) must implement Serializable.

(see http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html)

There seems to be no harm in implementing Serializable here since the Comparator has no internal state, so there's nothing to do.

@@ -126,7 +126,7 @@ public static long readUnsignedInt(ByteBuffer buffer, int index) {
* @return The integer read (MUST BE TREATED WITH SPECIAL CARE TO AVOID SIGNEDNESS)
*/
public static int readUnsignedIntLE(InputStream in) throws IOException {
return (in.read() << 8 * 0)
return (in.read() & 0xff)
Copy link
Contributor

Choose a reason for hiding this comment

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

I have been debating whether I should change this every time I saw it. :) I guess whoever wrote it liked the fact there was a regular pattern followed by each line.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have a bunch of other 8 * 0 in the file. Do we want to update those too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at this closer, it seems to be incorrect...

@@ -258,4 +259,15 @@ private void check(Type type, Object obj) {
assertEquals("The object read back should be the same as what was written.", obj, result);
}

@Test
public void testStructEquals() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding the test.

@asfbot
Copy link

asfbot commented Feb 28, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1879/
Test PASSed (JDK 8 and Scala 2.11).

@asfbot
Copy link

asfbot commented Feb 28, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1876/
Test PASSed (JDK 7 and Scala 2.10).

@asfbot
Copy link

asfbot commented Feb 28, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1877/
Test FAILed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented Mar 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1908/
Test FAILed (JDK 8 and Scala 2.11).

@asfbot
Copy link

asfbot commented Mar 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1906/
Test FAILed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented Mar 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1905/
Test FAILed (JDK 7 and Scala 2.10).

@asfbot
Copy link

asfbot commented Mar 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1926/
Test PASSed (JDK 7 and Scala 2.10).

@asfbot
Copy link

asfbot commented Mar 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1929/
Test PASSed (JDK 8 and Scala 2.11).

@asfbot
Copy link

asfbot commented Mar 1, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1927/
Test PASSed (JDK 8 and Scala 2.12).

@ijuma
Copy link
Contributor

ijuma commented Mar 2, 2017

@cmccabe, I added some tests, removed some unused (and untested) code and did a few tweaks:

ijuma@1ddf22b

If it looks good to you, please cherry-pick to your branch and I'll merge this PR.

@asfbot
Copy link

asfbot commented Mar 3, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1983/
Test FAILed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented Mar 3, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1985/
Test FAILed (JDK 8 and Scala 2.11).

@asfbot
Copy link

asfbot commented Mar 3, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1982/
Test FAILed (JDK 7 and Scala 2.10).

@cmccabe
Copy link
Contributor Author

cmccabe commented Mar 3, 2017

Thanks. I added the pull request to this patch series and rebased on trunk

@asfbot
Copy link

asfbot commented Mar 3, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1985/
Test FAILed (JDK 7 and Scala 2.10).

@asfbot
Copy link

asfbot commented Mar 3, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1986/
Test FAILed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented Mar 3, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1988/
Test FAILed (JDK 8 and Scala 2.11).

Copy link
Contributor

@ijuma ijuma left a comment

Choose a reason for hiding this comment

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

Thanks for the updates, LGTM. The test failures are caused by 573a6f3, which was merged with broken tests accidentally.

@asfgit asfgit closed this in d9b784e Mar 4, 2017
@cmccabe cmccabe deleted the KAFKA-4796 branch May 20, 2019 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants