|
25 | 25 |
|
26 | 26 | import java.lang.ref.Reference;
|
27 | 27 | import java.lang.ref.SoftReference;
|
| 28 | +import java.lang.reflect.InvocationTargetException; |
28 | 29 | import java.util.Map;
|
29 | 30 | import java.util.WeakHashMap;
|
30 | 31 |
|
@@ -62,15 +63,37 @@ public NativeMapped defaultValue() {
|
62 | 63 | }
|
63 | 64 |
|
64 | 65 | try {
|
65 |
| - return (NativeMapped)type.newInstance(); |
| 66 | + return (NativeMapped)type |
| 67 | + .getDeclaredConstructor() |
| 68 | + .newInstance(); |
| 69 | + } catch (IllegalAccessException e) { |
| 70 | + String msg = "Can't create an instance of " + type |
| 71 | + + ", requires a public no-arg constructor: " + e; |
| 72 | + throw new IllegalArgumentException(msg, e); |
| 73 | + } catch (IllegalArgumentException e) { |
| 74 | + String msg = "Can't create an instance of " + type |
| 75 | + + ", requires a public no-arg constructor: " + e; |
| 76 | + throw new IllegalArgumentException(msg, e); |
66 | 77 | } catch (InstantiationException e) {
|
67 | 78 | String msg = "Can't create an instance of " + type
|
68 |
| - + ", requires a no-arg constructor: " + e; |
69 |
| - throw new IllegalArgumentException(msg); |
70 |
| - } catch (IllegalAccessException e) { |
71 |
| - String msg = "Not allowed to create an instance of " + type |
72 |
| - + ", requires a public, no-arg constructor: " + e; |
73 |
| - throw new IllegalArgumentException(msg); |
| 79 | + + ", requires a public no-arg constructor: " + e; |
| 80 | + throw new IllegalArgumentException(msg, e); |
| 81 | + } catch (NoSuchMethodException e) { |
| 82 | + String msg = "Can't create an instance of " + type |
| 83 | + + ", requires a public no-arg constructor: " + e; |
| 84 | + throw new IllegalArgumentException(msg, e); |
| 85 | + } catch (SecurityException e) { |
| 86 | + String msg = "Can't create an instance of " + type |
| 87 | + + ", requires a public no-arg constructor: " + e; |
| 88 | + throw new IllegalArgumentException(msg, e); |
| 89 | + } catch (InvocationTargetException e) { |
| 90 | + if(e.getCause() instanceof RuntimeException) { |
| 91 | + throw (RuntimeException) e.getCause(); |
| 92 | + } else { |
| 93 | + String msg = "Can't create an instance of " + type |
| 94 | + + ", requires a public no-arg constructor: " + e; |
| 95 | + throw new IllegalArgumentException(msg, e); |
| 96 | + } |
74 | 97 | }
|
75 | 98 | }
|
76 | 99 | @Override
|
|
0 commit comments