Skip to content

Commit 1930153

Browse files
committed
fixup! fixup! fixup! fixup! - B PackageSettings only needs to support private ctor if the members are all static
lazy create
1 parent e7139a7 commit 1930153

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

approvaltests-util/src/main/java/org/packagesettings/PackageLevelSettings.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private static Map<String, Settings> getSettingsFor(String packageName, HashSet<
5050
{
5151
Class<?> clazz = loadClass(packageName + "." + PACKAGE_SETTINGS);
5252
Field[] declaredFields = clazz.getDeclaredFields();
53-
Object o = createInstance(clazz);
53+
Object o = null;
5454
for (Field field : declaredFields)
5555
{
5656
if (Modifier.isStatic(field.getModifiers()))
@@ -59,6 +59,10 @@ private static Map<String, Settings> getSettingsFor(String packageName, HashSet<
5959
}
6060
else
6161
{
62+
if (o == null)
63+
{
64+
o = createInstance(clazz);
65+
}
6266
settings.put(field.getName(), getFieldValue(field, o));
6367
}
6468
}
@@ -88,6 +92,7 @@ private static Settings getFieldValue(Field field, Object from)
8892
private static Object createInstance(Class<?> clazz) throws Exception
8993
{
9094
Constructor<?> constructor = clazz.getDeclaredConstructor();
95+
constructor.setAccessible(true);
9196
return constructor.newInstance();
9297
}
9398

0 commit comments

Comments
 (0)