You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/08/12 19:55:43 UTC
svn commit: r1695590 - in
/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6:
generic/Instruction.java generic/InstructionConstants.java
generic/PUSH.java util/BCELFactory.java
Author: sebb
Date: Wed Aug 12 17:55:43 2015
New Revision: 1695590
URL: http://svn.apache.org/r1695590
Log:
BCEL-237 non-empty final arrays should be private as they are mutable
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/InstructionConstants.java
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/PUSH.java
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/BCELFactory.java
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java?rev=1695590&r1=1695589&r2=1695590&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/Instruction.java Wed Aug 12 17:55:43 2015
@@ -114,7 +114,7 @@ public abstract class Instruction implem
public Instruction copy() {
Instruction i = null;
// "Constant" instruction, no need to duplicate
- if (InstructionConstants.INSTRUCTIONS[this.getOpcode()] != null) {
+ if (InstructionConstants.getInstruction(this.getOpcode()) != null) {
i = this;
} else {
try {
@@ -153,8 +153,9 @@ public abstract class Instruction implem
wide = true;
opcode = (short) bytes.readUnsignedByte();
}
- if (InstructionConstants.INSTRUCTIONS[opcode] != null) {
- return InstructionConstants.INSTRUCTIONS[opcode]; // Used predefined immutable object, if available
+ final Instruction instruction = InstructionConstants.getInstruction(opcode);
+ if (instruction != null) {
+ return instruction; // Used predefined immutable object, if available
}
switch (opcode) {
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/InstructionConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/InstructionConstants.java?rev=1695590&r1=1695589&r2=1695590&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/InstructionConstants.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/InstructionConstants.java Wed Aug 12 17:55:43 2015
@@ -165,7 +165,7 @@ public class InstructionConstants {
/** Get object via its opcode, for immutable instructions like
* branch instructions entries are set to null.
*/
- public static final Instruction[] INSTRUCTIONS = new Instruction[256];
+ private static final Instruction[] INSTRUCTIONS = new Instruction[256];
static {
INSTRUCTIONS[Constants.NOP] = NOP;
@@ -276,4 +276,13 @@ public class InstructionConstants {
INSTRUCTIONS[Constants.MONITORENTER] = MONITORENTER;
INSTRUCTIONS[Constants.MONITOREXIT] = MONITOREXIT;
}
+
+ /**
+ * Gets the Instruction.
+ * @param index the index, e.g. {@link Constants#RETURN}
+ * @return the entry from the private INSTRUCTIONS table
+ */
+ public static Instruction getInstruction(int index) {
+ return INSTRUCTIONS[index];
+ }
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/PUSH.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/PUSH.java?rev=1695590&r1=1695589&r2=1695590&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/PUSH.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/PUSH.java Wed Aug 12 17:55:43 2015
@@ -38,7 +38,7 @@ public final class PUSH implements Compo
*/
public PUSH(ConstantPoolGen cp, int value) {
if ((value >= -1) && (value <= 5)) {
- instruction = InstructionConstants.INSTRUCTIONS[Constants.ICONST_0 + value];
+ instruction = InstructionConstants.getInstruction(Constants.ICONST_0 + value);
} else if ((value >= -128) && (value <= 127)) {
instruction = new BIPUSH((byte) value);
} else if ((value >= -32768) && (value <= 32767)) {
@@ -54,7 +54,7 @@ public final class PUSH implements Compo
* @param value to be pushed
*/
public PUSH(ConstantPoolGen cp, boolean value) {
- instruction = InstructionConstants.INSTRUCTIONS[Constants.ICONST_0 + (value ? 1 : 0)];
+ instruction = InstructionConstants.getInstruction(Constants.ICONST_0 + (value ? 1 : 0));
}
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/BCELFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/BCELFactory.java?rev=1695590&r1=1695589&r2=1695590&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/BCELFactory.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/util/BCELFactory.java Wed Aug 12 17:55:43 2015
@@ -108,7 +108,7 @@ class BCELFactory extends EmptyVisitor {
private boolean visitInstruction( Instruction i ) {
short opcode = i.getOpcode();
- if ((InstructionConstants.INSTRUCTIONS[opcode] != null)
+ if ((InstructionConstants.getInstruction(opcode) != null)
&& !(i instanceof ConstantPushInstruction) && !(i instanceof ReturnInstruction)) { // Handled below
_out.println("il.append(InstructionConstants."
+ i.getName().toUpperCase(Locale.ENGLISH) + ");");