Commit b34efe51 authored by pcregut's avatar pcregut

Cleaner code + check that the encoded value is not null. Will raise a failure...

Cleaner code + check that the encoded value is not null. Will raise a failure otherwise and will avoid later errors hard to track.
parent efd5a2e9
......@@ -85,7 +85,7 @@ public class EncodedValueFactory {
encodedValue = new EncodedValueDouble(value);
break;
case Opcodes.VALUE_STRING:
encodedValue = new EncodedValueString(value);
encodedValue = new EncodedValueString((String) value);
break;
case Opcodes.VALUE_TYPE:
encodedValue = new EncodedValueType(value);
......@@ -174,7 +174,7 @@ public class EncodedValueFactory {
} else if (value instanceof Short) {
return new EncodedValueShort(value);
} else if (value instanceof String) {
return new EncodedValueString(value);
return new EncodedValueString((String) value);
}
// Test the Arrays.
......
......@@ -53,20 +53,13 @@ public class EncodedValueString extends EncodedValue {
/**
* Constructs the Encoded Value from its value.
* @param value the value.
* @param value the value. It cannot be null.
*/
public EncodedValueString(String value) {
if (value == null) throw new RuntimeException("EncodedValue");
this.value = value;
}
/**
* Constructs the Encoded Value from an Object containing a value.
* @param value the Object containing a value.
*/
public EncodedValueString(Object value) {
this.value = (String)value;
}
@Override
public byte[] encode(ConstantPool constantPool) {
int index = constantPool.getStringIndex(value);
......@@ -110,7 +103,7 @@ public class EncodedValueString extends EncodedValue {
return 0;
}
EncodedValueString ev = (EncodedValueString)encodedValue;
EncodedValueString ev = (EncodedValueString)encodedValue;
return value.compareTo(ev.value);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment