-
Notifications
You must be signed in to change notification settings - Fork 214
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
Misc IntelliJ warnings and fixes #884
Conversation
Integer.valueOf(value.substring(3,4),16).intValue(); | ||
Integer.valueOf(value.substring(1, 2), 16); | ||
Integer.valueOf(value.substring(2, 3), 16); | ||
Integer.valueOf(value.substring(3, 4), 16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here the indentation seems to have broken. Please keep it consistent with the surrounding indentation, even if that may seem strange. Consistency wins against beauty here, because we cannot just re-indent all files without breaking all pull-requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed in [b32d928]
Thank you
Integer.valueOf(value.substring(5,7),16).intValue(); | ||
Integer.valueOf(value.substring(1, 3), 16); | ||
Integer.valueOf(value.substring(3, 5), 16); | ||
Integer.valueOf(value.substring(5, 7), 16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed in [b32d928]
Thank you
buffer.add(Byte.valueOf((byte) ((frameHeader & 0xFF00) >>> 8))); | ||
buffer.add(Byte.valueOf((byte) (frameHeader & 0x00FF))); | ||
buffer.add((byte) ((frameHeader & 0xFF00) >>> 8)); | ||
buffer.add((byte) (frameHeader & 0x00FF)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it guaranteed that casting to byte will work in all cases here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The casting already happens inside the call to valueOf
, removing the manual boxing here doesn’t change anything about that.
@@ -90,10 +90,10 @@ public void readFilter( | |||
packet = new FlacFrame(payload); | |||
} else { | |||
firstHalfOfSyncHeaderFound = false; | |||
buffer.add(Byte.valueOf((byte) 0xFF)); | |||
buffer.add((byte) 0xFF); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the cast safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing, the casting isn’t changed, only the boxing is removed.
} | ||
} | ||
buffer.add(Byte.valueOf((byte) (data & 0xFF))); | ||
buffer.add((byte) (data & 0xFF)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the cast safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also safe. 🙂
} | ||
if(concludingPartialSegment != 0) { | ||
segmentSizes.add(Byte.valueOf(intToUnsignedByte(concludingPartialSegment))); | ||
segmentSizes.add(intToUnsignedByte(concludingPartialSegment)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two are also implicit casts. Are they safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s no implicit casting happening here, intToUnsignedByte
already returns a byte
, that would be an identity conversion, followed by a boxing conversion (JLS § 5.1.1, § 5.1.7).
Logger.error(this, "This should really not happen!", new Exception("FIXME")); | ||
handler.send(new ProtocolErrorMessage(ProtocolErrorMessage.INTERNAL_ERROR, false, "This should really not happen! See logs for details.", identifier, false)); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks much nicer! (but needs consistent indentation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally hate switch
statements and would much rather see this replaced with a different construct that actually hides all this ugliness (e.g. by a map or a strategy pattern or something) but that’s very much an issue for another day, this is fine. 🙂
@@ -499,7 +499,7 @@ public void handleMethodGET(URI uri, final HTTPRequest request, ToadletContext c | |||
//i now points to the proper location (equal, insertion point, or end-of-list) | |||
//maybe better called "reverseGroup"? | |||
List<PeerNodeStatus> peerGroup; | |||
if (i<max && locations.get(i).doubleValue()==location) { | |||
if (i<max && locations.get(i) ==location) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is == safe without the doubleValue()? This may cause type coercion to float.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, double
s are not coerced to float
s; in an equality comparison binary numeric promotion is performed, and as one of the operands is a double
, the other one is promoted to double
as well; as they are both already double
s, nothing bad at all will happen here. (JLS § 15.21.1, § 5.6.2.)
return ((DarknetPeerNodeStatus) firstNode).getTheirVisibility().compareTo(((DarknetPeerNodeStatus) secondNode).getTheirVisibility()); | ||
default: | ||
return super.customCompare(firstNode, secondNode, sortBy); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mind the indentation.
@@ -1103,8 +1103,7 @@ private static String getForceValue(FreenetURI key, long time) { | |||
throw new Error(e); | |||
} | |||
|
|||
String f = HexUtil.bytesToHex(SHA256.digest(bos.toByteArray())); | |||
return f; | |||
return HexUtil.bytesToHex(SHA256.digest(bos.toByteArray())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
default: | ||
isSet = false; | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation again (IntelliJ can have problems there)
@@ -322,7 +322,7 @@ | |||
window.__gwt_module_id = 0; | |||
</script></head> | |||
<body> | |||
<font face='arial' size='-1'>This html file is for Development Mode support.</font> | |||
<span style="font-family: arial; font-size: smaller; ">This html file is for Development Mode support.</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yikes, we still had those old styles in there! Good catch!
} catch (IllegalArgumentException e) { | ||
//Render the default page if unable to parse password prompt type. | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
case "delete": | ||
SecurityLevelsToadlet.sendCantDeleteMasterKeysFileInner(helper, core.node.getMasterPasswordFile().getPath(), newThreatLevel.name()); | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs consistent indentation again
@@ -87,8 +87,7 @@ public Inet4AddressMatcher(String cidrHostname) { | |||
*/ | |||
public static int convertToBytes(String address) { | |||
StringTokenizer addressTokens = new StringTokenizer(address, "."); | |||
int bytes = Integer.parseInt(addressTokens.nextToken()) << 24 | Integer.parseInt(addressTokens.nextToken()) << 16 | Integer.parseInt(addressTokens.nextToken()) << 8 | Integer.parseInt(addressTokens.nextToken()); | |||
return bytes; | |||
return Integer.parseInt(addressTokens.nextToken()) << 24 | Integer.parseInt(addressTokens.nextToken()) << 16 | Integer.parseInt(addressTokens.nextToken()) << 8 | Integer.parseInt(addressTokens.nextToken()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
src/freenet/io/comm/DMT.java
Outdated
@@ -1439,8 +1439,7 @@ public static Message createFNPVisibility(short visibility) { | |||
}}; | |||
|
|||
public static Message createFNPVoid() { | |||
Message msg = new Message(FNPVoid); | |||
return msg; | |||
return new Message(FNPVoid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
throw new MalformedURLException("Cannot write USKs as binary keys"); | ||
default: | ||
throw new MalformedURLException("Cannot write key of type " + keyType + " - do not know how"); | ||
} | ||
if(!keyType.equals("KSK")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is nice! (but indentation)
src/freenet/l10n/ISO639_3.java
Outdated
return Scope.Special; | ||
default: | ||
throw new IllegalArgumentException("Unknown scope abbreviation: " + abbreviation); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
src/freenet/l10n/ISO639_3.java
Outdated
return Type.Special; | ||
default: | ||
throw new IllegalArgumentException("Unknwon type abbreviation: " + abbreviation); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
src/freenet/node/Announcer.java
Outdated
@@ -302,8 +302,7 @@ protected void stop() { | |||
|
|||
public int getAnnouncementThreshold() { | |||
// First, do we actually need to announce? | |||
int target = Math.min(MIN_OPENNET_CONNECTED_PEERS, om.getNumberOfConnectedPeersToAimIncludingDarknet() / 2); | |||
return target; | |||
return Math.min(MIN_OPENNET_CONNECTED_PEERS, om.getNumberOfConnectedPeersToAimIncludingDarknet() / 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
src/freenet/support/Fields.java
Outdated
1000L * 1000L * 1000L, 1L << 30, | ||
1000L * 1000L * 1000L * 1000L, 1L << 40, | ||
1000L * 1000L * 1000L * 1000L * 1000, 1L << 50, | ||
1000L * 1000L * 1000L * 1000L * 1000L * 1000L, 1L << 60 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unable to find an issue with the indentation of the source file.
default: | ||
throw new NumberFormatException( | ||
"unknown time/date delta type: " + deltaTypeString); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the string switch already available in Java 8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, with constant expressions for the case statements. Had to check myself because I also remember something about it being loudly introduced at a much later version but that’s probably for non-constant expressions in the case statements. 🙂
@@ -219,7 +219,7 @@ public InsertExceptionMode getFirstCodeInsert() { | |||
} | |||
|
|||
public synchronized int getFirstCode() { | |||
return ((Integer) map.keySet().toArray()[0]).intValue(); | |||
return (Integer) map.keySet().toArray()[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would replace this with
return map.keySet().iterator().next();
and avoid the casting altogether.
buffer.add(Byte.valueOf((byte) ((frameHeader & 0xFF00) >>> 8))); | ||
buffer.add(Byte.valueOf((byte) (frameHeader & 0x00FF))); | ||
buffer.add((byte) ((frameHeader & 0xFF00) >>> 8)); | ||
buffer.add((byte) (frameHeader & 0x00FF)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The casting already happens inside the call to valueOf
, removing the manual boxing here doesn’t change anything about that.
@@ -90,10 +90,10 @@ public void readFilter( | |||
packet = new FlacFrame(payload); | |||
} else { | |||
firstHalfOfSyncHeaderFound = false; | |||
buffer.add(Byte.valueOf((byte) 0xFF)); | |||
buffer.add((byte) 0xFF); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing, the casting isn’t changed, only the boxing is removed.
} | ||
} | ||
buffer.add(Byte.valueOf((byte) (data & 0xFF))); | ||
buffer.add((byte) (data & 0xFF)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also safe. 🙂
} | ||
if(concludingPartialSegment != 0) { | ||
segmentSizes.add(Byte.valueOf(intToUnsignedByte(concludingPartialSegment))); | ||
segmentSizes.add(intToUnsignedByte(concludingPartialSegment)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s no implicit casting happening here, intToUnsignedByte
already returns a byte
, that would be an identity conversion, followed by a boxing conversion (JLS § 5.1.1, § 5.1.7).
default: | ||
throw new NumberFormatException( | ||
"unknown time/date delta type: " + deltaTypeString); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, with constant expressions for the case statements. Had to check myself because I also remember something about it being loudly introduced at a much later version but that’s probably for non-constant expressions in the case statements. 🙂
spaces back into tabs to match existing style
Closing. Will redo sometime in the future as smaller patches that can be merged or changed without holding up the whole PR. |
Assortment of fixes suggested by IntelliJ when analyzing the source code.
Code compiles and my node seems to be working.