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

Zero-length array allocation inspection (idea) #504

Open
wants to merge 103 commits into
base: master-MC1.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
dc9f9df
AbstractMod.java
RusTit Apr 5, 2018
2247599
AlvearyLogicStimulator.java
RusTit Apr 5, 2018
87d0f00
AnalystPageFruit.java
RusTit Apr 5, 2018
234b863
BlockDesign.java
RusTit Apr 5, 2018
2fe06eb
Botany.java remove override method. It is same with AbstractMod
RusTit Apr 5, 2018
f730dca
ComponentTankContainer.java
RusTit Apr 5, 2018
9306a88
ContainerCraftGUI.java
RusTit Apr 5, 2018
6c75184
DefaultMachineInventory.java
RusTit Apr 5, 2018
d0d8bb1
DefaultTankContainer.java
RusTit Apr 5, 2018
62d828a
Engineering.java
RusTit Apr 5, 2018
0e4c264
ErrorState.java
RusTit Apr 5, 2018
a81a986
WindowGenesis.java
RusTit Apr 5, 2018
e6ae7a7
TransferRequest.java
RusTit Apr 5, 2018
f42565a
WindowCompartment.java
RusTit Apr 5, 2018
2f551a0
MachineComponent.java, ManagerMachine.java, ItemSerumArray.java, Rota…
RusTit Apr 5, 2018
f25638a
FlowerRoot.java - remove method override getRandomTemplate. It is sam…
RusTit Apr 5, 2018
491bca8
Merge branch 'master-MC1.12' into memory_zero_Array
RusTit Apr 7, 2018
f9efc57
Refactoring and clean up
RusTit Apr 7, 2018
3164761
Small refactor
RusTit Apr 7, 2018
67f6167
Small refactor
RusTit Apr 7, 2018
9e66628
Small refactor
RusTit Apr 7, 2018
56e3a6c
AlleleHelper.java - add final to vars in methods.
RusTit Apr 7, 2018
1546d7c
Refactoring BreedingSystem.java
RusTit Apr 7, 2018
fffb54d
Gene.java
RusTit Apr 7, 2018
a5dbd38
Code cleanup
RusTit Apr 7, 2018
0ea7cbc
Code cleanup
RusTit Apr 7, 2018
1b5ab81
Code cleanup
RusTit Apr 7, 2018
ffcf137
Refactor to use EmptyHelper.EMPTY_STRING
RusTit Apr 7, 2018
71a9cb6
Clean up fieldkit
RusTit Apr 7, 2018
a50ac55
Clean up WindowGenesis.java
RusTit Apr 7, 2018
2700726
Clean up ControlEnergyBar.java
RusTit Apr 7, 2018
1a4cd05
Clean up ControlErrorState.java
RusTit Apr 7, 2018
5e134aa
Add final to vars
RusTit Apr 7, 2018
c72e4c1
Small refactoring in ControlPlayerInventory.java
RusTit Apr 7, 2018
56d499e
Refactor and localize ControlProgressBase.java
RusTit Apr 7, 2018
0334c8d
Add final to vars
RusTit Apr 7, 2018
5ac0e50
Add Nullable annotation to label
RusTit Apr 7, 2018
7019466
Add final to vars
RusTit Apr 7, 2018
0c08015
Add final to vars
RusTit Apr 7, 2018
71ea3e4
Improve localise in ControlUser.java
RusTit Apr 7, 2018
f01b9f4
Refactor to use EmptyHelper.EMPTY_STRING
RusTit Apr 7, 2018
0aacdca
Small refactoring in ContainerCraftGUI.java
RusTit Apr 7, 2018
5f57ea2
Small refactoring in CustomSlot.java
RusTit Apr 7, 2018
fb23c58
Add final to vars GuiCraftGUI.java
RusTit Apr 7, 2018
5268728
Add final to vars Window.java
RusTit Apr 7, 2018
2b6cc7f
Add final to vars renderer
RusTit Apr 7, 2018
c3e9f8b
Add final to vars renderer
RusTit Apr 7, 2018
4195e2b
Refactor to use org.apache.commons.lang3.StringUtils.EMPTY
RusTit Apr 8, 2018
4255589
Fix crashing with NullPointerException in Tolerance.toString()
RusTit Apr 8, 2018
15a0204
Add final to vars. Rename min and sec in ru_lang.
RusTit Apr 8, 2018
fa368b1
Refactor getWidget()
RusTit Apr 8, 2018
64ed74f
Use Constants.EXTRA_BEES_MOD_ID in ExtraBeesIntegration.java
RusTit Apr 8, 2018
f06f9d4
Remove this.setUnlocalizedName("genesis"); already invoked in super
RusTit Apr 8, 2018
555847f
Remove this.setUnlocalizedName("field_kit"); already invoked in super
RusTit Apr 8, 2018
02f81fa
Remove this.setUnlocalizedName(name); already invoked in super
RusTit Apr 8, 2018
c948c9e
Add final to vars.
RusTit Apr 8, 2018
2127146
Small refactoring in FluidContainerType.java
RusTit Apr 8, 2018
f88d84e
Add @Nullable annotation in FluidHandlerItemBinnie.java
RusTit Apr 8, 2018
7e4bd23
Add final to vars.
RusTit Apr 8, 2018
f1b0bab
Improve FluidContainerType.java and ItemFluidContainer.java localizing.
RusTit Apr 8, 2018
96bd7d8
Add final and some refactoring in ManagerLiquid.java
Apr 9, 2018
a8b4f61
ManagerLiquid.java
Apr 9, 2018
d91181d
Add @Nullable annotation in ITankMachine.java
Apr 9, 2018
5a0ba07
Add final to vars in TileEntityMachineBase.java
Apr 9, 2018
989164b
Add final to vars in ErrorState.java
Apr 10, 2018
cd1f24e
Remove unused anymore setOutputSides in BaseSlot.java
Apr 10, 2018
389c08a
Add final to vars and StringUtils.Empty for ""
Apr 10, 2018
7d6c42a
Refactor duplication code in ComponentInventorySlots.java, ComponentT…
Apr 10, 2018
888c4f7
Various final and annotations.
Apr 10, 2018
b82624e
Improve localize SlotValidator.java
Apr 10, 2018
2dee6f8
ControlSlot.java tooltip loc improve
Apr 10, 2018
b050cee
Small refactor TankSlot.java
Apr 10, 2018
6fa260b
ComponentPowerReceptor.java - remove null checks from world var. But …
Apr 10, 2018
e697607
Various final, NBT keys const.
Apr 10, 2018
ebc62ca
Various final, NBT keys const.
Apr 10, 2018
bbb3242
Compartment refactoring start.
Apr 10, 2018
853f7b3
SearchDialog.java code refactoring.
Apr 10, 2018
f4ed704
Revert back checking for null.
Apr 10, 2018
f8b9fe4
Improve SearchDialog.java localizing
Apr 10, 2018
8534327
Update ComponentPowerReceptor.java
RusTit Apr 10, 2018
f1c7186
Update ComponentPowerReceptor.java
RusTit Apr 10, 2018
537ab84
Fix border painting in SearchDialog
Apr 11, 2018
ec8f386
Small clean up
Apr 11, 2018
e879445
Remove unused empty Integer[] array anymore
Apr 11, 2018
2b66108
Remove final from vars
Apr 13, 2018
c3a6edc
Merge remote-tracking branch 'main/HEAD' into memory_zero_Array
Apr 13, 2018
a25d01b
Method names should start with a lowercase letter.
RusTit Apr 14, 2018
6db93dc
Improve variable.
RusTit Apr 14, 2018
2706a2e
Change checking for string emptiness.
RusTit Apr 14, 2018
35833f9
Improve intends
RusTit Apr 14, 2018
f9a801f
Improve localise in ControlLiquidTank.java
RusTit Apr 14, 2018
aa1ad08
Merge branch 'master-MC1.12' into memory_zero_Array
Apr 15, 2018
5f740e8
Merge remote-tracking branch 'origin/memory_zero_Array' into memory_z…
Apr 15, 2018
8bd8a46
Refactor tab slots array init.
Apr 15, 2018
0ec3efb
Extract createTab from lambda
Apr 15, 2018
0595121
Refactoring compartment window.
Apr 15, 2018
1de8fe8
Code clean up
Apr 16, 2018
894fc28
Extract slide and localize
Apr 16, 2018
b1fca09
Extract method createTabNameControl
Apr 16, 2018
483d57c
Extract method createTabIconControl
Apr 16, 2018
241d31e
Refactoring and localizing compartment
Apr 16, 2018
01b2c61
indentation
Apr 16, 2018
839e476
Remove unused comment.
Apr 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions botany/src/main/java/binnie/botany/Botany.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ public IBinnieGUID[] getGUIDs() {
return BotanyGUI.values();
}

@Override
public Class<?>[] getConfigs() {
return new Class[0];
}

@Override
public IPacketID[] getPacketIDs() {
return PacketID.values();
Expand Down
5 changes: 0 additions & 5 deletions botany/src/main/java/binnie/botany/genetics/FlowerRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,6 @@ public IAllele[] getDefaultTemplate() {
return alleles;
}

@Override
public IAllele[] getRandomTemplate(Random rand) {
return speciesTemplates.values().toArray(new IAllele[0][])[rand.nextInt(speciesTemplates.values().size())];
}

@Override
public ArrayList<IFlowerMutation> getMutations(boolean shuffle) {
if (shuffle) {
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/binnie/core/AbstractMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import binnie.core.network.IPacketProvider;
import binnie.core.network.packet.MessageBinnie;
import binnie.core.proxy.IProxyCore;
import binnie.core.util.EmptyHelper;

public abstract class AbstractMod implements IPacketProvider, IInitializable {
protected final List<IInitializable> modules;
Expand All @@ -40,15 +41,15 @@ public AbstractMod() {

@Override
public IPacketID[] getPacketIDs() {
return new IPacketID[0];
return EmptyHelper.PACKET_IDS_EMPTY;
}

public IBinnieGUID[] getGUIDs() {
return new IBinnieGUID[0];
return EmptyHelper.BINNIE_GUIDS_EMPTY;
}

public Class<?>[] getConfigs() {
return new Class[0];
return EmptyHelper.CLASS_ARRAY_EMPTY;
}

public abstract IProxyCore getProxy();
Expand Down
9 changes: 3 additions & 6 deletions core/src/main/java/binnie/core/block/BlockMetadata.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package binnie.core.block;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;

import net.minecraft.block.Block;
Expand Down Expand Up @@ -40,20 +39,18 @@ public static void getDrops(NonNullList<ItemStack> drops, IBlockMetadata block,
}

public static boolean breakBlock(IBlockMetadata blockMetadata, @Nullable EntityPlayer player, World world, BlockPos pos) {
List<ItemStack> drops = new ArrayList<>();
List<ItemStack> drops = null;
Block block = (Block) blockMetadata;
TileEntityMetadata tile = TileEntityMetadata.getTile(world, pos);
if (tile != null && !tile.hasDroppedBlock()) {
drops = block.getDrops(world, pos, world.getBlockState(pos), 0);
}
boolean hasBeenBroken = world.setBlockToAir(pos);
if (hasBeenBroken && !world.isRemote && drops.size() > 0 && (player == null || !player.capabilities.isCreativeMode)) {
if (hasBeenBroken && !world.isRemote && drops != null && (player == null || !player.capabilities.isCreativeMode)) {
for (ItemStack drop : drops) {
spawnAsEntity(world, pos, drop);
}
if (tile != null) {
tile.dropBlock();
}
tile.dropBlock();
}
return hasBeenBroken;
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/binnie/core/block/TileEntityMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public static ItemStack getItemStack(final Block block, final int damage) {
return itemStack;
}

private static final int MAX_ITEM_DAMAGE = 16387;
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor

@temp1011 temp1011 Apr 13, 2018

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.


public static void setItemDamage(final ItemStack item, final int i) {
item.setItemDamage((i < 16387) ? i : 16387);
item.setItemDamage((i < MAX_ITEM_DAMAGE) ? i : MAX_ITEM_DAMAGE);
final NBTTagCompound tag = new NBTTagCompound();
tag.setInteger("meta", i);
item.setTagCompound(tag);
Expand Down Expand Up @@ -76,7 +78,7 @@ public NBTTagCompound getUpdateTag() {
@Override
public void readFromNBT(final NBTTagCompound nbt) {
super.readFromNBT(nbt);
if(world!=null)
if (world != null)
setTileMetadata(nbt.getInteger("meta"), world.isRemote);
else
this.meta = nbt.getInteger("meta");
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/binnie/core/circuits/BinnieCircuit.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public class BinnieCircuit implements ICircuit {
private final int limit;
private final List<String> tooltips;

private static final int TOOLTIPS_ARRAY_CAPACITY = 8;

public BinnieCircuit(final String uid, final int limit, final ICircuitLayout layout, final ItemStack itemStack) {
this.tooltips = new ArrayList<>();
this.tooltips = new ArrayList<>(TOOLTIPS_ARRAY_CAPACITY);
this.uid = "for.binnie.circuit." + uid;
this.limit = limit;
ChipsetManager.circuitRegistry.registerCircuit(this);
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/binnie/core/config/ConfigProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.apache.commons.lang3.StringUtils;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface ConfigProperty {
String key();

String category() default "";
String category() default StringUtils.EMPTY;

String[] comment() default {};

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/binnie/core/genetics/AlleleHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Locale;
import java.util.regex.Pattern;

import binnie.core.util.EmptyHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.WordUtils;

import forestry.api.core.EnumHumidity;
Expand Down Expand Up @@ -205,12 +205,12 @@ private static String getUid(String key, String valueName, boolean needCapitaliz
if (needCapitalize) {
valueName = WordUtils.capitalize(valueName.toLowerCase(Locale.ENGLISH));
}
valueName = PATTERN_REPLACEMENT.matcher(valueName).replaceAll(EmptyHelper.EMPTY_STRING);
valueName = PATTERN_REPLACEMENT.matcher(valueName).replaceAll(StringUtils.EMPTY);
return "forestry." + key + valueName;
}

private static String toAlleleDisplay(@Nullable String key, String valueName) {
String name = PATTERN_REPLACEMENT.matcher(valueName.toLowerCase()).replaceAll(EmptyHelper.EMPTY_STRING);
String name = PATTERN_REPLACEMENT.matcher(valueName.toLowerCase()).replaceAll(StringUtils.EMPTY);
if (key == null) {
return I18N.localise("forestry.allele." + name);
}
Expand Down
Loading