private ReadWriteLock getLockInProcessQueue(ProcessQueue pq) { try { return (ReadWriteLock) FieldUtils.readDeclaredField(pq, "lockTreeMap", true); } catch (IllegalAccessException e) { return null; } } }
/** * Reads the named {@code public} {@link Field}. Only the class of the specified object will be considered. * * @param target * the object to reflect, must not be {@code null} * @param fieldName * the field name to obtain * @return the value of the field * @throws IllegalArgumentException * if {@code target} is {@code null}, or the field name is blank or empty or could not be found * @throws IllegalAccessException * if the named field is not {@code public} */ public static Object readDeclaredField(final Object target, final String fieldName) throws IllegalAccessException { return readDeclaredField(target, fieldName, false); }
/** * This is temporary workaround to bypass the validation stage of the * compiler while *still* doing the additional_validate stage. We are * bypassing the validation stage because it does a deep validation that we * don't have all the parts for yet in the offline compiler. Rather than * stop all work on that, we bypass it so that we can still do useful things * like find all your types, find all your methods, etc. * */ @SuppressWarnings("unchecked") private void callAdditionalPassVisitor(ApexCompiler compiler) { try { List<CodeUnit> allUnits = (List<CodeUnit>) FieldUtils.readDeclaredField(compiler, "allUnits", true); CompilerContext compilerContext = (CompilerContext) FieldUtils.readDeclaredField(compiler, "compilerContext", true); for (CodeUnit unit : allUnits) { Method getOperation = CompilerStage.ADDITIONAL_VALIDATE.getDeclaringClass() .getDeclaredMethod("getOperation"); getOperation.setAccessible(true); CompilerOperation operation = (CompilerOperation) getOperation .invoke(CompilerStage.ADDITIONAL_VALIDATE); operation.invoke(compilerContext, unit); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e); } } }
@Test public void testReadDeclaredNamedFieldForceAccess() throws Exception { try { FieldUtils.readDeclaredField(publicChild, null, true); fail("a null field name should cause an IllegalArgumentException"); } catch (final IllegalArgumentException e) { FieldUtils.readDeclaredField(publicChild, "", true); fail("an empty field name should cause an IllegalArgumentException"); } catch (final IllegalArgumentException e) { FieldUtils.readDeclaredField(publicChild, " ", true); fail("a blank field name should cause an IllegalArgumentException"); } catch (final IllegalArgumentException e) { FieldUtils.readDeclaredField(null, "none", true); fail("a null target should cause an IllegalArgumentException"); } catch (final IllegalArgumentException e) { FieldUtils.readDeclaredField(publicChild, "s", true); fail("expected IllegalArgumentException"); } catch (final IllegalArgumentException e) { assertEquals("ss", FieldUtils.readDeclaredField(publiclyShadowedChild, "s", true)); assertEquals("ss", FieldUtils.readDeclaredField(privatelyShadowedChild, "s", true)); try { FieldUtils.readDeclaredField(publicChild, "b", true); fail("expected IllegalArgumentException"); } catch (final IllegalArgumentException e) {
@Test public void testReadDeclaredNamedField() throws Exception { try { FieldUtils.readDeclaredField(publicChild, null); fail("a null field name should cause an IllegalArgumentException"); } catch (final IllegalArgumentException e) { FieldUtils.readDeclaredField(publicChild, ""); fail("an empty field name should cause an IllegalArgumentException"); } catch (final IllegalArgumentException e) { FieldUtils.readDeclaredField(publicChild, " "); fail("a blank field name should cause an IllegalArgumentException"); } catch (final IllegalArgumentException e) { FieldUtils.readDeclaredField(null, "none"); fail("a null target should cause an IllegalArgumentException"); } catch (final IllegalArgumentException e) { FieldUtils.readDeclaredField(publicChild, "s"); fail("expected IllegalArgumentException"); } catch (final IllegalArgumentException e) { assertEquals("ss", FieldUtils.readDeclaredField(publiclyShadowedChild, "s")); try { FieldUtils.readDeclaredField(privatelyShadowedChild, "s"); fail("expected IllegalArgumentException"); } catch (final IllegalArgumentException e) { FieldUtils.readDeclaredField(publicChild, "b");
nodes = (Parent) FieldUtils.readDeclaredField(parentPopup.getSkin().getNode(), "itemsContainer", true); } catch (IllegalAccessException e) { e.printStackTrace();
assertEquals("S", FieldUtils.readDeclaredField(publiclyShadowedChild, "s", true)); FieldUtils.writeDeclaredField(publiclyShadowedChild, "b", Boolean.FALSE, true); assertEquals(Boolean.FALSE, FieldUtils.readDeclaredField(publiclyShadowedChild, "b", true)); FieldUtils.writeDeclaredField(publiclyShadowedChild, "i", Integer.valueOf(0), true); assertEquals(Integer.valueOf(0), FieldUtils.readDeclaredField(publiclyShadowedChild, "i", true)); FieldUtils.writeDeclaredField(publiclyShadowedChild, "d", Double.valueOf(0.0), true); assertEquals(Double.valueOf(0.0), FieldUtils.readDeclaredField(publiclyShadowedChild, "d", true)); assertEquals("S", FieldUtils.readDeclaredField(privatelyShadowedChild, "s", true)); FieldUtils.writeDeclaredField(privatelyShadowedChild, "b", Boolean.FALSE, true); assertEquals(Boolean.FALSE, FieldUtils.readDeclaredField(privatelyShadowedChild, "b", true)); FieldUtils.writeDeclaredField(privatelyShadowedChild, "i", Integer.valueOf(0), true); assertEquals(Integer.valueOf(0), FieldUtils.readDeclaredField(privatelyShadowedChild, "i", true)); FieldUtils.writeDeclaredField(privatelyShadowedChild, "d", Double.valueOf(0.0), true); assertEquals(Double.valueOf(0.0), FieldUtils.readDeclaredField(privatelyShadowedChild, "d", true));
private ReadWriteLock getLockInProcessQueue(ProcessQueue pq) { try { return (ReadWriteLock) FieldUtils.readDeclaredField(pq, "lockTreeMap", true); } catch (IllegalAccessException e) { return null; } } }
assertEquals("S", FieldUtils.readDeclaredField(publiclyShadowedChild, "s")); FieldUtils.writeDeclaredField(publiclyShadowedChild, "b", Boolean.FALSE); assertEquals(Boolean.FALSE, FieldUtils.readDeclaredField(publiclyShadowedChild, "b")); FieldUtils.writeDeclaredField(publiclyShadowedChild, "i", Integer.valueOf(0)); assertEquals(Integer.valueOf(0), FieldUtils.readDeclaredField(publiclyShadowedChild, "i")); FieldUtils.writeDeclaredField(publiclyShadowedChild, "d", Double.valueOf(0.0)); assertEquals(Double.valueOf(0.0), FieldUtils.readDeclaredField(publiclyShadowedChild, "d"));
@SuppressWarnings("unchecked") private static <T> T getField(final Object target, final String fieldName) throws IllegalAccessException { return (T) FieldUtils.readDeclaredField(target, fieldName, true); } }
@SuppressWarnings("unchecked") private static <T> T getField(final Object target, final String fieldName) throws IllegalAccessException { return (T) FieldUtils.readDeclaredField(target, fieldName, true); } }
private ReadWriteLock getLockInProcessQueue(ProcessQueue pq) { try { return (ReadWriteLock) FieldUtils.readDeclaredField(pq, "lockTreeMap", true); } catch (IllegalAccessException e) { return null; } } }
/** * Reads the named {@code public} {@link Field}. Only the class of the specified object will be considered. * * @param target * the object to reflect, must not be {@code null} * @param fieldName * the field name to obtain * @return the value of the field * @throws IllegalArgumentException * if {@code target} is {@code null}, or the field name is blank or empty or could not be found * @throws IllegalAccessException * if the named field is not {@code public} */ public static Object readDeclaredField(final Object target, final String fieldName) throws IllegalAccessException { return readDeclaredField(target, fieldName, false); }
/** * Reads the named {@code public} {@link Field}. Only the class of the specified object will be considered. * * @param target * the object to reflect, must not be {@code null} * @param fieldName * the field name to obtain * @return the value of the field * @throws IllegalArgumentException * if {@code target} is {@code null}, or the field name is blank or empty or could not be found * @throws IllegalAccessException * if the named field is not {@code public} */ public static Object readDeclaredField(final Object target, final String fieldName) throws IllegalAccessException { return readDeclaredField(target, fieldName, false); }
/** * Reads the named {@code public} {@link Field}. Only the class of the specified object will be considered. * * @param target * the object to reflect, must not be {@code null} * @param fieldName * the field name to obtain * @return the value of the field * @throws IllegalArgumentException * if {@code target} is {@code null}, or the field name is blank or empty or could not be found * @throws IllegalAccessException * if the named field is not {@code public} */ public static Object readDeclaredField(final Object target, final String fieldName) throws IllegalAccessException { return readDeclaredField(target, fieldName, false); }
private boolean checkUnique(Serializable target, List<String> columnNames) throws IllegalAccessException { if (columnNames.isEmpty()) { return true; } Map<String, Object> eqs = new HashMap<>(); for (String col : columnNames) { String c = StringUtils.removeEnd(col, "_id"); eqs.put(c, FieldUtils.readDeclaredField(target, c)); } return sessionFactory.getCurrentSession().createCriteria(clazz).add(Restrictions.allEq(eqs)).setProjection(Projections.rowCount()).uniqueResult().equals(0L); } }
@Override public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) { SqlMapGeneratorConfiguration smgc = context.getSqlMapGeneratorConfiguration(); try { Document document = (Document) FieldUtils.readDeclaredField(sqlMap, "document", true); File targetFile = getTargetFile(smgc.getTargetPackage(), sqlMap.getFileName()); if (!targetFile.exists()) { // 第一次生成直接使用当前生成的文件 return true; } visitAndMerge(document, targetFile); } catch (ShellException | IOException | IllegalAccessException | DocumentException e) { e.printStackTrace(); } return true; }
@Override public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) { SqlMapGeneratorConfiguration smgc = context.getSqlMapGeneratorConfiguration(); try { Document document = (Document) FieldUtils.readDeclaredField(sqlMap, "document", true); File targetFile = getTargetFile(smgc.getTargetPackage(), sqlMap.getFileName()); if (!targetFile.exists()) { // 第一次生成直接使用当前生成的文件 return true; } visitAndMerge(document, targetFile); } catch (ShellException | IOException | IllegalAccessException | DocumentException e) { e.printStackTrace(); } return true; }
@Override public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) { try { // use reflect to fix the root comment Document document = (Document) FieldUtils.readDeclaredField(sqlMap, "document", true); ExtendedDocument extendedDocument = new ExtendedDocument(document); FieldUtils.writeDeclaredField(sqlMap, "document", extendedDocument, true); if (context.getCommentGenerator() instanceof CommentGenerator) { CommentGenerator cg = (CommentGenerator) context.getCommentGenerator(); cg.addSqlMapFileComment(extendedDocument); } } catch (IllegalAccessException e) { e.printStackTrace(); } return true; }
private String getInitStackTrace(Session session) throws IllegalAccessException { SessionDelegate sessionDelegate = (SessionDelegate) FieldUtils.readDeclaredField(session, "sd", true); SessionStats sessionStats = sessionDelegate.getSessionStats(); return sessionStats.getInitStackTrace(); }