-
Notifications
You must be signed in to change notification settings - Fork 59
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
Zero-length array allocation inspection (idea) #504
base: master-MC1.12
Are you sure you want to change the base?
Conversation
…tedOreIngredient.java
…e as in parent class.
01634d4
to
f9efc57
Compare
@Nedelosk please review. |
No problem, but it can take some time. |
@@ -40,8 +40,10 @@ public static ItemStack getItemStack(final Block block, final int damage) { | |||
return itemStack; | |||
} | |||
|
|||
private static final int MAX_ITEM_DAMAGE = 16387; |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea, I was trying to find this value (binnie, forestry, forge) but no successed
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm enums are weird, I guess they are being constructed before static. This is fine then.
@@ -57,11 +57,13 @@ public String getText() { | |||
@Override | |||
@SideOnly(Side.CLIENT) | |||
public void onRenderBackground(int guiWidth, int guiHeight) { | |||
Object texture = CraftGUITexture.BUTTON_DISABLED; | |||
Object texture; |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I introduced the proposed changes, but it seems that the static analyzer worked correctly without them.
@@ -42,15 +42,15 @@ public void onValueChanged(final IClassification branch) { | |||
} | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is using spaces for indentation, the one above is tabs
@@ -193,11 +193,11 @@ public void getHelpTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) { | |||
if (slot != null) { | |||
tooltip.add(slot.getName()); | |||
if (tooltipFlag.isAdvanced()) { | |||
Collection<EnumFacing> inputSides = slot.getInputSides(); | |||
Collection<EnumFacing> inputSides = slot.getInputSides(); |
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 line indents with spaces
if (inputSides.size() > 0) { | ||
tooltip.add(TextFormatting.GRAY + I18N.localise(ModId.CORE, "gui.side.insert", MachineSide.asString(inputSides))); | ||
} | ||
Collection<EnumFacing> outputSides = slot.getOutputSides(); | ||
Collection<EnumFacing> outputSides = slot.getOutputSides(); |
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 line indents with spaces
@@ -53,7 +52,7 @@ public ItemStack getStack(IItemMiscProvider type, int size) { | |||
@SideOnly(Side.CLIENT) | |||
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()); |
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 line indents with spaces
@@ -67,7 +66,7 @@ public void registerModel(Item item, IModelManager manager) { | |||
|
|||
@Override | |||
public String getItemStackDisplayName(final ItemStack stack) { | |||
IItemMiscProvider item = this.getItem(stack.getItemDamage()); | |||
IItemMiscProvider item = this.getItem(stack.getItemDamage()); |
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 line indents with spaces
if ((!FluidRegistry.registerFluid(bFluid)) || (FluidRegistry.addBucketForFluid(bFluid))) { | ||
Log.error("Liquid registered incorrectly - {} ", fluid.getIdentifier()); | ||
} | ||
} |
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 line indents with spaces
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 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.