mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Throw FormatException if BdfList index is out of bounds.
This commit is contained in:
@@ -29,13 +29,19 @@ public class BdfList extends Vector<Object> {
|
||||
super(items);
|
||||
}
|
||||
|
||||
private boolean isInRange(int index) {
|
||||
return index >= 0 && index < size();
|
||||
}
|
||||
|
||||
public Boolean getBoolean(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o instanceof Boolean) return (Boolean) o;
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
public Boolean getOptionalBoolean(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o == null || o == NULL_VALUE) return null;
|
||||
if (o instanceof Boolean) return (Boolean) o;
|
||||
@@ -43,12 +49,14 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public Boolean getBoolean(int index, Boolean defaultValue) {
|
||||
if (!isInRange(index)) return defaultValue;
|
||||
Object o = get(index);
|
||||
if (o instanceof Boolean) return (Boolean) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public Long getLong(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o instanceof Long) return (Long) o;
|
||||
if (o instanceof Integer) return ((Integer) o).longValue();
|
||||
@@ -58,6 +66,7 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public Long getOptionalLong(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o == null || o == NULL_VALUE) return null;
|
||||
if (o instanceof Long) return (Long) o;
|
||||
@@ -68,6 +77,7 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public Long getLong(int index, Long defaultValue) {
|
||||
if (!isInRange(index)) return defaultValue;
|
||||
Object o = get(index);
|
||||
if (o instanceof Long) return (Long) o;
|
||||
if (o instanceof Integer) return ((Integer) o).longValue();
|
||||
@@ -77,6 +87,7 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public Double getDouble(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o instanceof Double) return (Double) o;
|
||||
if (o instanceof Float) return ((Float) o).doubleValue();
|
||||
@@ -84,6 +95,7 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public Double getOptionalDouble(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o == null || o == NULL_VALUE) return null;
|
||||
if (o instanceof Double) return (Double) o;
|
||||
@@ -92,6 +104,7 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public Double getDouble(int index, Double defaultValue) {
|
||||
if (!isInRange(index)) return defaultValue;
|
||||
Object o = get(index);
|
||||
if (o instanceof Double) return (Double) o;
|
||||
if (o instanceof Float) return ((Float) o).doubleValue();
|
||||
@@ -99,12 +112,14 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public String getString(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o instanceof String) return (String) o;
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
public String getOptionalString(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o == null || o == NULL_VALUE) return null;
|
||||
if (o instanceof String) return (String) o;
|
||||
@@ -112,12 +127,14 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public String getString(int index, String defaultValue) {
|
||||
if (!isInRange(index)) return defaultValue;
|
||||
Object o = get(index);
|
||||
if (o instanceof String) return (String) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public byte[] getRaw(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o instanceof byte[]) return (byte[]) o;
|
||||
if (o instanceof Bytes) return ((Bytes) o).getBytes();
|
||||
@@ -125,6 +142,7 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public byte[] getOptionalRaw(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o == null || o == NULL_VALUE) return null;
|
||||
if (o instanceof byte[]) return (byte[]) o;
|
||||
@@ -133,6 +151,7 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public byte[] getRaw(int index, byte[] defaultValue) {
|
||||
if (!isInRange(index)) return defaultValue;
|
||||
Object o = get(index);
|
||||
if (o instanceof byte[]) return (byte[]) o;
|
||||
if (o instanceof Bytes) return ((Bytes) o).getBytes();
|
||||
@@ -140,12 +159,14 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public BdfList getList(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o instanceof BdfList) return (BdfList) o;
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
public BdfList getOptionalList(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o == null || o == NULL_VALUE) return null;
|
||||
if (o instanceof BdfList) return (BdfList) o;
|
||||
@@ -153,12 +174,14 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public BdfList getList(int index, BdfList defaultValue) {
|
||||
if (!isInRange(index)) return defaultValue;
|
||||
Object o = get(index);
|
||||
if (o instanceof BdfList) return (BdfList) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public BdfDictionary getDictionary(int index) throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
||||
throw new FormatException();
|
||||
@@ -166,6 +189,7 @@ public class BdfList extends Vector<Object> {
|
||||
|
||||
public BdfDictionary getOptionalDictionary(int index)
|
||||
throws FormatException {
|
||||
if (!isInRange(index)) throw new FormatException();
|
||||
Object o = get(index);
|
||||
if (o == null || o == NULL_VALUE) return null;
|
||||
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
||||
@@ -173,6 +197,7 @@ public class BdfList extends Vector<Object> {
|
||||
}
|
||||
|
||||
public BdfDictionary getDictionary(int index, BdfDictionary defaultValue) {
|
||||
if (!isInRange(index)) return defaultValue;
|
||||
Object o = get(index);
|
||||
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
||||
return defaultValue;
|
||||
|
||||
Reference in New Issue
Block a user