|
4 | 4 | import java.io.IOException;
|
5 | 5 | import java.io.InputStream;
|
6 | 6 | import java.io.UnsupportedEncodingException;
|
| 7 | +import java.lang.reflect.Field; |
| 8 | +import java.lang.reflect.Method; |
7 | 9 | import java.lang.invoke.MethodHandle;
|
8 | 10 | import java.lang.invoke.MethodHandles;
|
9 | 11 | import java.lang.invoke.MethodType;
|
10 | 12 | import java.lang.ProcessBuilder.Redirect;
|
11 | 13 | import java.lang.Thread;
|
| 14 | +import java.lang.NoSuchFieldException; |
12 | 15 | import java.math.BigDecimal;
|
13 | 16 | import java.math.BigInteger;
|
14 | 17 | import java.math.RoundingMode;
|
|
29 | 32 | import java.security.MessageDigest;
|
30 | 33 | import java.security.NoSuchAlgorithmException;
|
31 | 34 | import java.util.AbstractMap;
|
| 35 | +import java.util.Arrays; |
32 | 36 | import java.util.ArrayList;
|
33 | 37 | import java.util.Collections;
|
34 | 38 | import java.util.EnumSet;
|
35 | 39 | import java.util.HashMap;
|
| 40 | +import java.util.Iterator; |
36 | 41 | import java.util.List;
|
37 | 42 | import java.util.Map;
|
38 | 43 | import java.util.Properties;
|
@@ -4848,10 +4853,10 @@ public static long getpid(ThreadContext tc) {
|
4848 | 4853 | */
|
4849 | 4854 | try {
|
4850 | 4855 | java.lang.management.RuntimeMXBean runtime = java.lang.management.ManagementFactory.getRuntimeMXBean();
|
4851 |
| - java.lang.reflect.Field jvm = runtime.getClass().getDeclaredField("jvm"); |
| 4856 | + Field jvm = runtime.getClass().getDeclaredField("jvm"); |
4852 | 4857 | jvm.setAccessible(true);
|
4853 | 4858 | Object mgmt = jvm.get(runtime);
|
4854 |
| - java.lang.reflect.Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId"); |
| 4859 | + Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId"); |
4855 | 4860 | pid_method.setAccessible(true);
|
4856 | 4861 | return (Integer)pid_method.invoke(mgmt);
|
4857 | 4862 | }
|
@@ -5942,9 +5947,36 @@ public static String join_literal(String[] parts) {
|
5942 | 5947 | private static BigInteger getBI(ThreadContext tc, SixModelObject obj) {
|
5943 | 5948 | if (obj instanceof P6bigintInstance)
|
5944 | 5949 | return ((P6bigintInstance)obj).value;
|
5945 |
| - /* What follows is a bit of a hack, relying on the first field being the |
5946 |
| - * big integer. */ |
5947 |
| - obj.get_attribute_native(tc, null, null, 0); |
| 5950 | + /* What follows is a bit of a hack. |
| 5951 | + * Unlike previously, we cannot rely on field_0 being the bigint, |
| 5952 | + * because we might have an allomorph coming in. |
| 5953 | + * To correctly handle that case we need to find the field on obj |
| 5954 | + * which contains a BigInteger in field_0, in case we failed to |
| 5955 | + * find the BigInteger in field_0 of obj. |
| 5956 | + */ |
| 5957 | + try { |
| 5958 | + obj.get_attribute_native(tc, null, null, 0); |
| 5959 | + } |
| 5960 | + catch (RuntimeException RTE) { |
| 5961 | + List<Field> interestingFields = new ArrayList<Field>(Arrays.asList(obj.getClass().getFields())); |
| 5962 | + for( Iterator<Field> it = interestingFields.iterator(); it.hasNext(); ) { |
| 5963 | + if( !it.next().getName().startsWith("field_") ) { |
| 5964 | + it.remove(); |
| 5965 | + } |
| 5966 | + } |
| 5967 | + |
| 5968 | + for( Field field : interestingFields ) { |
| 5969 | + try { |
| 5970 | + SixModelObject curAttr = (SixModelObject) field.get(obj); |
| 5971 | + try { |
| 5972 | + curAttr.get_attribute_native(tc, null, null, 0); |
| 5973 | + } catch (RuntimeException innerRTE) { |
| 5974 | + } |
| 5975 | + } catch(IllegalAccessException iae) { |
| 5976 | + // this really shouldn't happen, but... |
| 5977 | + } |
| 5978 | + } |
| 5979 | + } |
5948 | 5980 | return (BigInteger)tc.native_j;
|
5949 | 5981 | }
|
5950 | 5982 |
|
|
0 commit comments