Zero-length array allocation inspection (idea)#504
Zero-length array allocation inspection (idea)#504RusTit wants to merge 103 commits intoForestryMC:master-MC1.12from
Conversation
…tedOreIngredient.java
…e as in parent class.
01634d4 to
f9efc57
Compare
|
@Nedelosk please review. |
|
No problem, but it can take some time. |
| return itemStack; | ||
| } | ||
|
|
||
| private static final int MAX_ITEM_DAMAGE = 16387; |
There was a problem hiding this comment.
Any idea what the significance of this number is?
I thought it might be a power of 2 minus 1, but the nearest power of 2 is 2^14 (16384) which is also a weird number.
There was a problem hiding this comment.
No idea, I was trying to find this value (binnie, forestry, forge) but no successed
There was a problem hiding this comment.
Max seems to be OreDictionary.WILDCARD_VALUE at 32767 so this doesn't even have the right number of bits.
| @Nullable | ||
| private static Pattern PATTERN; | ||
|
|
||
| private static Pattern GetPattern() { |
There was a problem hiding this comment.
Method names should start with a lowercase letter.
Actually I think this should just be created statically instead of using a singleton getter, since it is not very expensive to create and does not pull in lots of other classes.
private static Pattern PATTERN = Pattern.compile("_", Pattern.LITERAL);There was a problem hiding this comment.
In this case it is not. At first version I do like you describe. But after mc run, it crushed with NullPointException in
@Override
public String toString() {
return GetPattern().matcher(super.toString().toLowerCase(Locale.ENGLISH)).replaceAll(StringUtils.EMPTY);
}
Where is some issue with object creating (initial). At moment then toString invoked PATTERN will be null.
There was a problem hiding this comment.
Hm enums are weird, I guess they are being constructed before static. This is fine then.
| @SideOnly(Side.CLIENT) | ||
| public void onRenderBackground(int guiWidth, int guiHeight) { | ||
| Object texture = CraftGUITexture.BUTTON_DISABLED; | ||
| Object texture; |
There was a problem hiding this comment.
One nice use of final is for cases like this. You can make final Object texture; and the static analyzer will complain "variable 'texture' might not have been initialized" if there is a case where it is not set.
There was a problem hiding this comment.
I introduced the proposed changes, but it seems that the static analyzer worked correctly without them.
| this.branchDescription.clear(); | ||
| String desc = branch.getDescription(); | ||
| if (desc == null || Objects.equals(desc, "") || desc.contains("for.")) { | ||
| if (desc == null || desc.length() == 0 || desc.contains("for.")) { |
There was a problem hiding this comment.
You can use org.apache.commons.lang3.StringUtils#isEmpty to check desc
| for (int row = 0; row < rowCount; ++row) { | ||
| for (int column = 0; column < columnCount; ++column) { | ||
| final ControlSlot slot = new ControlSlot.Builder(this, column * 18, row * 18) | ||
| .assign(InventoryType.PLAYER,column + row * columnCount); |
There was a problem hiding this comment.
this line is using spaces for indentation, the one above is tabs
| tooltip.add(slot.getName()); | ||
| if (tooltipFlag.isAdvanced()) { | ||
| Collection<EnumFacing> inputSides = slot.getInputSides(); | ||
| Collection<EnumFacing> inputSides = slot.getInputSides(); |
| tooltip.add(TextFormatting.GRAY + I18N.localise(ModId.CORE, "gui.side.insert", MachineSide.asString(inputSides))); | ||
| } | ||
| Collection<EnumFacing> outputSides = slot.getOutputSides(); | ||
| Collection<EnumFacing> outputSides = slot.getOutputSides(); |
| public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { | ||
| super.addInformation(stack, worldIn, tooltip, flagIn); | ||
| IItemMiscProvider item = this.getItem(stack.getItemDamage()); | ||
| IItemMiscProvider item = this.getItem(stack.getItemDamage()); |
| @Override | ||
| public String getItemStackDisplayName(final ItemStack stack) { | ||
| IItemMiscProvider item = this.getItem(stack.getItemDamage()); | ||
| IItemMiscProvider item = this.getItem(stack.getItemDamage()); |
| if ((!FluidRegistry.registerFluid(bFluid)) || (FluidRegistry.addBucketForFluid(bFluid))) { | ||
| Log.error("Liquid registered incorrectly - {} ", fluid.getIdentifier()); | ||
| } | ||
| } |
mezz
left a comment
There was a problem hiding this comment.
there are indentation issues in the latest commits
|
Please do not add more commits on to this PR, it needs to be reviewed and merged but that gets harder with more commits. |
|
Ok, but to make clear, where is still some bugs:
|
|
Item icon painting bug appears not only in the search window. |
|
If you have specific fixes for the changes made in this PR, I think that is fine. |
|
Not yet. I do not know how to fix a bug with rendering. I will fix the error with the key a little later with separate commits (will be last in this PR) |
|
Apparently there is no bug with keys. |
|
Tabs indent or spaces? |
Text:
Reports on allocations of arrays with known lengths of zero. Since array lengths in Java are non-modifiable, it is almost always possible to share zero-length arrays, rather than repeatedly allocating new zero-length arrays. Such sharing may provide useful optimizations in program runtime or footprint. Note that this inspection does not report zero-length arrays allocated as static final fields, as it is assumed that those arrays are being used to implement array sharing.
And also I removed two methods. They are the same as those of the parent class.