Skip to content

Commit

Permalink
Fixed issue where extending classes couldn't be handled by handlers
Browse files Browse the repository at this point in the history
Example: ArrayLists didn't get deserialized, the list handler returned false when it was passed to canHandle.
This was fixed by checking the isAssignableFrom in reverse order (ArrayLists can be assigned to Lists, not vice-versa)
  • Loading branch information
SwanX1 committed Apr 23, 2022
1 parent 33a9db5 commit 66d3c81
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION=3.0.1
VERSION=3.0.2
GROUP=org.infernalstudios
ARTIFACT=config
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ default Class<?> getType() {
* Tests if the config element's type extends the given class
*/
default boolean extendsFrom(Class<?> clazz) {
return clazz.isAssignableFrom(getType());
return getType().isAssignableFrom(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public PrimitiveConfigElement(Field field, IConfigElementHandler<T, ?> handler)

@Override
public boolean extendsFrom(Class<?> clazz) {
return clazz.isAssignableFrom(this.primitiveType) || super.extendsFrom(clazz);
return this.primitiveType.isAssignableFrom(clazz) || super.extendsFrom(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public Boolean deserialize(Boolean obj) {

@Override
public boolean canHandle(Class<?> clazz) {
return clazz.equals(Boolean.class) || clazz.equals(Boolean.TYPE) || clazz.isAssignableFrom(Boolean.class) || clazz.isAssignableFrom(Boolean.TYPE);
return Boolean.class.equals(clazz) || Boolean.TYPE.equals(clazz) || Boolean.class.isAssignableFrom(clazz) || Boolean.TYPE.isAssignableFrom(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ public Double deserialize(Number obj) {

@Override
public boolean canHandle(Class<?> clazz) {
return clazz.equals(Double.class) || clazz.equals(Double.TYPE) || clazz.isAssignableFrom(Double.class) || clazz.isAssignableFrom(Double.TYPE);
return Double.class.equals(clazz) || Double.TYPE.equals(clazz) || Double.class.isAssignableFrom(clazz) || Double.TYPE.isAssignableFrom(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ public Float deserialize(Number obj) {

@Override
public boolean canHandle(Class<?> clazz) {
return clazz.equals(Float.class) || clazz.equals(Float.TYPE) || clazz.isAssignableFrom(Float.class) || clazz.isAssignableFrom(Float.TYPE);
return Float.class.equals(clazz) || Float.TYPE.equals(clazz) || Float.class.isAssignableFrom(clazz) || Float.TYPE.isAssignableFrom(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ public Integer deserialize(Number obj) {

@Override
public boolean canHandle(Class<?> clazz) {
return clazz.equals(Integer.class) || clazz.equals(Integer.TYPE) || clazz.isAssignableFrom(Integer.class) || clazz.isAssignableFrom(Integer.TYPE);
return Integer.class.equals(clazz) || Integer.TYPE.equals(clazz) || Integer.class.isAssignableFrom(clazz) || Integer.TYPE.isAssignableFrom(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public List deserialize(List obj) {

@Override
public boolean canHandle(Class<?> clazz) {
return (clazz.equals(List.class) || clazz.isAssignableFrom(List.class));
return (List.class.equals(clazz) || List.class.isAssignableFrom(clazz));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public String deserialize(String obj) {

@Override
public boolean canHandle(Class<?> clazz) {
return clazz.equals(String.class) || clazz.isAssignableFrom(String.class);
return String.class.equals(clazz) || String.class.isAssignableFrom(clazz);
}
}
30 changes: 15 additions & 15 deletions src/main/java/org/infernalstudios/config/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ public static Class<?> getPrimitive(Class<?> clazz) {
Objects.requireNonNull(clazz, "clazz must not be null");
if (clazz.isPrimitive()) {
return clazz;
} else if (clazz.equals(Boolean.class)) {
} else if (Boolean.class.equals(clazz)) {
return Boolean.TYPE;
} else if (clazz.equals(Byte.class)) {
} else if (Byte.class.equals(clazz)) {
return Byte.TYPE;
} else if (clazz.equals(Character.class)) {
} else if (Character.class.equals(clazz)) {
return Character.TYPE;
} else if (clazz.equals(Short.class)) {
} else if (Short.class.equals(clazz)) {
return Short.TYPE;
} else if (clazz.equals(Integer.class)) {
} else if (Integer.class.equals(clazz)) {
return Integer.TYPE;
} else if (clazz.equals(Long.class)) {
} else if (Long.class.equals(clazz)) {
return Long.TYPE;
} else if (clazz.equals(Float.class)) {
} else if (Float.class.equals(clazz)) {
return Float.TYPE;
} else if (clazz.equals(Double.class)) {
} else if (Double.class.equals(clazz)) {
return Double.TYPE;
} else {
return null;
Expand All @@ -42,13 +42,13 @@ public static boolean isNumber(Class<?> clazz) {
clazz = getPrimitive(clazz);
}
return (
clazz.isAssignableFrom(Number.class) ||
clazz.equals(Byte.TYPE) ||
clazz.equals(Short.TYPE) ||
clazz.equals(Integer.TYPE) ||
clazz.equals(Long.TYPE) ||
clazz.equals(Float.TYPE) ||
clazz.equals(Double.TYPE)
Number.class.isAssignableFrom(clazz) ||
Byte.TYPE.equals(clazz) ||
Short.TYPE.equals(clazz) ||
Integer.TYPE.equals(clazz) ||
Long.TYPE.equals(clazz) ||
Float.TYPE.equals(clazz) ||
Double.TYPE.equals(clazz)
);
}

Expand Down

0 comments on commit 66d3c81

Please sign in to comment.