145 // if the returned material is null
146 if (material == null) {
147 // reassign the material with the default block
148 material = ConfigurationManager.INSTANCE.getBlockMenuCategory().getDefaultBlock();149 // insert the player to the blocks database
150 Databases.BLOCK_DATABASE.insert(bridgePlayer);
151 }
79 BoardPlayer value = toBoardPlayer(key, resultSet);
80 final BridgePlayer player = playerService.getIfPresent(key);
81 if (player != null && player.getScores().isEmpty()) {
82 value = new BoardPlayer(value.getName(), 0, key, value.getScore()); 83 }
84
85 boardPlayer.set(value);
107 URL url = new URL(String.format(UPDATE_URL, pluginID));
108 HttpURLConnection connection = (HttpURLConnection) url.openConnection();
109 connection.addRequestProperty("User-Agent", USER_AGENT);
110 responseCode = connection.getResponseCode();111
112 JsonParser parser = new JsonParser();
113 JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream()));
A local variable is being assigned within a return statement. This may be either a typo in a comparison or an unnecessary operation.
Review this code and either directly return the local variable or convert the assignment into a comparison as intended.
Consider the following two (rather contrived) examples:
Typos
Boolean checkForSomething(int s) {
return s = 3;
}
Here, this method returns a Boolean
value, but its return statement appears to return the result of assigning an int
value. This code will fail to compile. It is likely that this was caused by the omission of an extra =
character, turning the comparison into an assignment.
Useless operations
Boolean return4() {
int s;
return s = 4;
}
Here, the method returns an integer value, but its return statement assigns to s
within the return statement itself. This works because when treated as expressions, assignments evaluate to the assigned value.
This is also needless, since the same effect could be achieved by simply returning the assigned value directly.
If the assignment is a typo, just change the =
into a more suitable operator.
Boolean checkForSomething(int s) {
return s != 3;
}
If it is just a superfluous operation, just return the assigned expression:
Boolean return4() {
return 4;
}
In this case, s
can be removed entirely, since its only usage is within the erroneous assignment.