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

Upgrade reflectutils to jdk 11+ #2

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,30 @@
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<rules>
<requireJavaVersion>
<version>[11,)</version>
</requireJavaVersion>
</rules>

</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module org.azeckoski.reflectutils {
requires commons.beanutils;
requires java.base;
requires java.desktop;
requires java.sql;
requires java.xml;

exports org.azeckoski.reflectutils;
}
31 changes: 13 additions & 18 deletions src/main/java/org/azeckoski/reflectutils/ClassData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InaccessibleObjectException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
Expand Down Expand Up @@ -139,14 +140,12 @@ protected void getAllThings(final Class<?> type, final List<Field> fList, final
fList.add(field);
} else {
try {
AccessController.doPrivileged(new PrivilegedAction<T>() {
public T run() {
field.setAccessible(true);
return null;
}
AccessController.doPrivileged((PrivilegedAction<T>) () -> {
field.setAccessible(true);
return null;
});
fList.add(field);
} catch (SecurityException e) {
} catch (InaccessibleObjectException e) {
// oh well, this does not get added then
}
}
Expand All @@ -160,14 +159,12 @@ public T run() {
mList.add(method);
} else {
try {
AccessController.doPrivileged(new PrivilegedAction<T>() {
public T run() {
method.setAccessible(true);
return null;
}
AccessController.doPrivileged((PrivilegedAction<T>) () -> {
method.setAccessible(true);
return null;
});
mList.add(method);
} catch (SecurityException e) {
} catch (InaccessibleObjectException e) {
// oh well, this does not get added then
}
}
Expand All @@ -182,14 +179,12 @@ public T run() {
cList.add((Constructor<T>)constructor);
} else {
try {
AccessController.doPrivileged(new PrivilegedAction<T>() {
public T run() {
constructor.setAccessible(true);
return null;
}
AccessController.doPrivileged((PrivilegedAction<T>) () -> {
constructor.setAccessible(true);
return null;
});
cList.add((Constructor<T>)constructor);
} catch (SecurityException e) {
} catch (InaccessibleObjectException e) {
// oh well, this does not get added then
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static <T> T convertToType(Class<T> targetType, Object value, DateFormat[
} else {
// try to get the long value out of the string
try {
long num = new Long(stringValue);
long num = Long.parseLong(stringValue);
if (num > 30000000l) {
// must be a UTC time code, also, we only lost a week since 1970 so whatever
return (T) toDate(targetType, num);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static <T> T convertToType(Class<T> targetType, Object value) {

// Handle Boolean
if (value instanceof Boolean) {
return (T) toNumber(sourceType, targetType, ((Boolean)value).booleanValue() ? 1 : 0);
return (T) toNumber(sourceType, targetType, (Boolean) value ? 1 : 0);
}

// Handle Date
Expand Down Expand Up @@ -142,7 +142,7 @@ private static Number toNumber(Class<?> sourceType, Class<?> targetType, Number
throw new UnsupportedOperationException("source (" + sourceType + ") value ("
+ value + ") is too small for target (" + targetType + ")");
}
return new Byte(value.byteValue());
return value.byteValue();
}

// Short
Expand All @@ -156,7 +156,7 @@ private static Number toNumber(Class<?> sourceType, Class<?> targetType, Number
throw new UnsupportedOperationException("source (" + sourceType + ") value ("
+ value + ") is too small for target (" + targetType + ")");
}
return new Short(value.shortValue());
return value.shortValue();
}

// Integer
Expand All @@ -170,12 +170,12 @@ private static Number toNumber(Class<?> sourceType, Class<?> targetType, Number
throw new UnsupportedOperationException("source (" + sourceType + ") value ("
+ value + ") is too small for target (" + targetType + ")");
}
return new Integer(value.intValue());
return value.intValue();
}

// Long
if (targetType.equals(Long.class)) {
return new Long(value.longValue());
return value.longValue();
}

// Float
Expand All @@ -184,12 +184,12 @@ private static Number toNumber(Class<?> sourceType, Class<?> targetType, Number
throw new UnsupportedOperationException("source (" + sourceType + ") value ("
+ value + ") is too large for target (" + targetType + ")");
}
return new Float(value.floatValue());
return value.floatValue();
}

// Double
if (targetType.equals(Double.class)) {
return new Double(value.doubleValue());
return value.doubleValue();
}

// BigDecimal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,16 @@ public static String escapeForJSON(String string) {
public static final int CURRENT = 1;
public static final int NEXT = 2;

private static Map<Character, Character> escapes = new HashMap<Character, Character>();
private static Map<Character, Character> escapes = new HashMap<>();
static {
escapes.put(new Character('"'), new Character('"'));
escapes.put(new Character('\\'), new Character('\\'));
escapes.put(new Character('/'), new Character('/'));
escapes.put(new Character('b'), new Character('\b'));
escapes.put(new Character('f'), new Character('\f'));
escapes.put(new Character('n'), new Character('\n'));
escapes.put(new Character('r'), new Character('\r'));
escapes.put(new Character('t'), new Character('\t'));
escapes.put(Character.valueOf('"'), Character.valueOf('"'));
escapes.put(Character.valueOf('\\'), Character.valueOf('\\'));
escapes.put(Character.valueOf('/'), Character.valueOf('/'));
escapes.put(Character.valueOf('b'), Character.valueOf('\b'));
escapes.put(Character.valueOf('f'), Character.valueOf('\f'));
escapes.put(Character.valueOf('n'), Character.valueOf('\n'));
escapes.put(Character.valueOf('r'), Character.valueOf('\r'));
escapes.put(Character.valueOf('t'), Character.valueOf('\t'));
}

protected static char[] hex = "0123456789ABCDEF".toCharArray();
Expand Down Expand Up @@ -608,7 +608,7 @@ private Object string() {
if (c == 'u') {
add(unicode());
} else {
Object value = escapes.get(new Character(c));
Object value = escapes.get(Character.valueOf(c));
if (value != null) {
add(((Character) value).charValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ public void testConvertObject() {

// equivalent conversion also should be instantaneous since no conversion happens
assertEquals(123, (int) convertUtils.convert(123, int.class) );
assertEquals(123, (int) convertUtils.convert(new Integer(123), int.class) );
assertEquals(123, (int) convertUtils.convert(123, int.class) );
assertEquals("123", convertUtils.convert("123", String.class) );
assertEquals(abc, convertUtils.convert(abc, String[].class) );

// object conversion should be instant
assertEquals(new Integer(123), (Integer) convertUtils.convert(123, Object.class) );
assertEquals(123, convertUtils.convert(123, Object.class));
assertEquals("123", convertUtils.convert("123", Object.class) );

// now do actual conversions
assertEquals(123, (int) convertUtils.convert("123", int.class) );
assertEquals("123", convertUtils.convert("123", String.class) );
assertEquals(new Integer(123), convertUtils.convert("123", Integer.class) );
assertEquals(Integer.valueOf(123), convertUtils.convert("123", Integer.class) );

// array to scalar
assertEquals(123, (int) convertUtils.convert(new int[] {123,456}, int.class) );
assertEquals(123, (int) convertUtils.convert(new String[] {"123","456"}, int.class) );

// scalar to array
int[] nums = new int[] {123};
int[] nums;
nums = convertUtils.convert(123, int[].class);
assertEquals(123, nums[0]);
nums = convertUtils.convert("123", int[].class);
Expand Down Expand Up @@ -155,13 +155,13 @@ public void testConvertString() {
ConversionUtils convertUtils = new ConversionUtils();

assertEquals(3, convertUtils.convertString("3", int.class));
assertEquals(new Integer(3), convertUtils.convertString("3", Integer.class));
assertEquals(3, convertUtils.convertString("3", Integer.class));
int[] intArray = (int[]) convertUtils.convertString("3", int[].class);
assertEquals(3, intArray[0]);
assertEquals("XXX", convertUtils.convertString("XXX", Integer.class));
}

private enum TestEnum {ONE, TWO, THREE};
private enum TestEnum {ONE, TWO, THREE}
public void testConvertEnums() {
ConversionUtils convertUtils = new ConversionUtils();

Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/azeckoski/reflectutils/DeepUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
public class DeepUtilsTest extends TestCase {

/**
* Test method for {@link org.sakaiproject.ReflectUtils.util.reflect.ReflectUtil#deepClone(java.lang.Object, int, java.lang.String[])}.
* Test method for {@link org.azeckoski.reflectutils.DeepUtils#deepClone(Object, int, String[])}.
*/
public void testClone() {
DeepUtils deepUtils = new DeepUtils();
Expand Down Expand Up @@ -118,7 +118,7 @@ public void testClone() {
}

/**
* Test method for {@link org.sakaiproject.ReflectUtils.util.reflect.ReflectUtil#deepCopy(java.lang.Object, java.lang.Object, int, java.lang.String[], boolean)}.
* Test method for {@link org.azeckoski.reflectutils.DeepUtils#deepCopy(Object, Object, int, String[], boolean)}.
*/
public void testCopy() {
DeepUtils deepUtils = new DeepUtils();
Expand Down Expand Up @@ -232,7 +232,7 @@ public void testPopulate() {
assertEquals("OLD,BLUE", target.getMyString());

// objects
properties.put("myInt", new Long(222));
properties.put("myInt", 222L);
properties.put("myString", 55555);
results = deepUtils.populate(target, properties);
assertNotNull(results);
Expand All @@ -256,7 +256,7 @@ public void testPopulateFromParams() {
assertNotNull(results);
assertEquals(3, results.size());
assertNotNull(target);
assertEquals(new Long(1000), target.getId());
assertEquals(Long.valueOf(1000), target.getId());
assertEquals("OLD", target.getExtra());
assertEquals("33", target.getEntityId());
assertEquals(null, target.getBool());
Expand Down Expand Up @@ -328,7 +328,7 @@ public void testObjectToMap() {
// get non-null object data
m = (Map<String, Object>) map.get("testEntity");
assertNotNull(m);
assertEquals(new Long(3), m.get("id"));
assertEquals(3L, m.get("id"));
assertEquals("33", m.get("entityId"));
assertTrue(m.containsKey("extra"));
assertEquals(null, m.get("extra")); // null
Expand Down Expand Up @@ -368,7 +368,7 @@ public void testObjectToMap() {
// get non-null object data
m = (Map<String, Object>) map.get("testEntity");
assertNotNull(m);
assertEquals(new Long(3), m.get("id"));
assertEquals(3L, m.get("id"));
assertEquals("33", m.get("entityId"));
assertFalse(m.containsKey("extra"));
assertEquals(null, m.get("extra")); // null
Expand Down Expand Up @@ -441,7 +441,7 @@ public void testPopulateFromNestedMap() {
m.put("myString", "string");
deepUtils.populate(tc, m);
assertEquals("F1", tc.myField);
assertEquals(new Integer(123), tc.fieldInt);
assertEquals(Integer.valueOf(123), tc.fieldInt);
assertEquals(234, tc.getMyInt());
assertEquals("string", tc.getMyString());

Expand Down
Loading
Loading