public boolean get(Object object) { try { return this.field.getBoolean(object); } catch (Exception e) { return false; } }
/** * Gets the value of a static <code>boolean</code> field. * * @param field Field object whose value is returned. * @return the value of the <code>boolean</code> field */ public static boolean getBoolean(Field field) { checkStatic(field); try { return field.getBoolean(null); } catch (Exception exp) { throw translate(exp); } }
public boolean getReflectZ() throws Exception { return f_z.getBoolean(t); }
/** * Gets the value of an instance <code>boolean</code> field. * * @param field Field object whose value is returned. * @param obj the object to extract the <code>boolean</code> value * from * @return the value of the <code>boolean</code> field */ public static boolean getBoolean(Field field, Object obj) { try { return field.getBoolean(obj); } catch (Exception exp) { throw translate(exp); } }
public boolean getBoolean(Object o) throws IllegalArgumentException, IllegalAccessException { return this.field.getBoolean(o); }
@Override void serialize(AbstractHessianOutput out, Object obj, Field field) throws IOException { boolean value = false; try { value = field.getBoolean(obj); } catch (IllegalAccessException e) { log.log(Level.FINE, e.toString(), e); } out.writeBoolean(value); } }
public static boolean callSetAndGetBoolean(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException { thiz.setBoolean(obj, !thiz.getBoolean(obj)); return thiz.getBoolean(obj); }
public static boolean callSetBoolean(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException { thiz.setBoolean(obj, true); return thiz.getBoolean(obj); }
public final boolean getBooleanValue(Object obj) throws IllegalAccessException { if (!isAndroid && memOffset >= 0) { return FSTUtil.unFlaggedUnsafe.getBoolean(obj, memOffset); } return field.getBoolean(obj); }
private static boolean getStaticBooleanField(Class cls, String name, boolean def) { try { Field field = cls.getDeclaredField(name); field.setAccessible(true); return field.getBoolean(null); } catch (ReflectiveOperationException e) { return def; } }
public final boolean getBooleanValue(Object obj) throws IllegalAccessException { if (!isAndroid && memOffset >= 0) { return FSTUtil.unFlaggedUnsafe.getBoolean(obj, memOffset); } return field.getBoolean(obj); }
public static Activity getActivity() { Class activityThreadClass = Class.forName("android.app.ActivityThread"); Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null); Field activitiesField = activityThreadClass.getDeclaredField("mActivities"); activitiesField.setAccessible(true); Map<Object, Object> activities = (Map<Object, Object>) activitiesField.get(activityThread); if(activities == null) return null; for (Object activityRecord : activities.values()) { Class activityRecordClass = activityRecord.getClass(); Field pausedField = activityRecordClass.getDeclaredField("paused"); pausedField.setAccessible(true); if (!pausedField.getBoolean(activityRecord)) { Field activityField = activityRecordClass.getDeclaredField("activity"); activityField.setAccessible(true); Activity activity = (Activity) activityField.get(activityRecord); return activity; } } }
private static boolean getBoolField(HdfsSpout spout, String fieldName) throws NoSuchFieldException, IllegalAccessException { Field readerFld = HdfsSpout.class.getDeclaredField(fieldName); readerFld.setAccessible(true); return readerFld.getBoolean(spout); }
protected void positionSelectorCompat(int position, View sel) { final Rect selectorRect = mSelectorRect; selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom()); // Adjust for selection padding. selectorRect.left -= mSelectionLeftPadding; selectorRect.top -= mSelectionTopPadding; selectorRect.right += mSelectionRightPadding; selectorRect.bottom += mSelectionBottomPadding; try { // AbsListView.mIsChildViewEnabled controls the selector's state so we need to // modify it's value final boolean isChildViewEnabled = mIsChildViewEnabled.getBoolean(this); if (sel.isEnabled() != isChildViewEnabled) { mIsChildViewEnabled.set(this, !isChildViewEnabled); if (position != INVALID_POSITION) { refreshDrawableState(); } } } catch (IllegalAccessException e) { e.printStackTrace(); } } /**
@Override public String toString() { Field[] fields = getFields(this); String r=""; for( Field field : fields ){ String name = field.getName(); Class cl = field.getType(); try{ if( cl.isPrimitive() ){ if( cl == Boolean.TYPE ){ boolean curval = field.getBoolean(this); if( curval ) r += " -"+name; } else if( cl == Integer.TYPE ) r+=" -"+name+"="+field.getInt(this); else if( cl == Float.TYPE ) r+=" -"+name+"="+field.getFloat(this); else if( cl == Double.TYPE ) r+=" -"+name+"="+field.getDouble(this); else if( cl == Long.TYPE ) r+=" -"+name+"="+field.getLong(this); else continue; } else if( cl == String.class ) if (field.get(this)!=null) r+=" -"+name+"="+field.get(this); } catch( Exception e ) { Log.err("Argument failed with ",e); } } return r; } }
private static boolean setBoundsChecking(boolean enabled) throws Exception { Field field = BoundsChecking.class.getDeclaredField("BOUNDS_CHECKING_ENABLED"); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); boolean old = field.getBoolean(null); field.setAccessible(true); field.set(null, enabled); return old; }
/** * Returns the value of the field in the specified object as a {@code * boolean}. This reproduces the effect of {@code object.fieldName} * <p> * If this field is static, the object argument is ignored. * Otherwise, if the object is {@code null}, a NullPointerException is * thrown. If the object is not an instance of the declaring class of the * method, an IllegalArgumentException is thrown. * <p> * If this Field object is enforcing access control (see AccessibleObject) * and this field is not accessible from the current context, an * IllegalAccessException is thrown. * * @param object * the object to access * @return the field value * @throws NullPointerException * if the object is {@code null} and the field is non-static * @throws IllegalArgumentException * if the object is not compatible with the declaring class * @throws IllegalAccessException * if this field is not accessible */ public boolean getBoolean(Object object) throws IllegalAccessException, IllegalArgumentException { checkAccess(object, false); checkReceiver(object); return getBoolean(object, getType(), Boolean.TYPE); }
/** * Deal with javax SSL properties */ private static void makeNullStaticField(final Class sslClass) { Field[] fields = sslClass.getDeclaredFields(); for (int index = 0; index < fields.length; ++index) { Field field = fields[index]; try { if (Modifier.isStatic(field.getModifiers())) { field.setAccessible(true); if (field.getClass().equals(boolean.class)) { field.setBoolean(null, false); assertFalse(field.getBoolean(null)); } else if (sslClass.isInstance(field.get(null))) { field.set(null, null); assertNull(field.get(null)); } } } catch (IllegalAccessException ex) { getLogWriter().warning("Exception while clearing static SSL field.", ex); } catch (ClassCastException ex) { getLogWriter().warning("Exception while clearing static SSL field.", ex); } } }
@Override public String toString() { StringBuilder result = new StringBuilder( type.toString() ); if ( convertToQuery ) { result.append( " (as query)" ); } String sep = ": "; for ( Field field : getClass().getDeclaredFields() ) { if ( field.getType() == boolean.class ) { boolean value; field.setAccessible( true ); try { value = field.getBoolean( this ); } catch ( IllegalAccessException e ) { throw new RuntimeException( e ); } result.append( sep ).append( '.' ).append( field.getName() ).append( "() == " ).append( value ); sep = ", "; } } return result.toString(); }
@Test public void test() throws Exception { StatefulSerializer<Serializable> s = new CompactJavaSerializer<>(null); s.init(new TransientStateRepository()); ClassLoader loaderW = createClassNameRewritingLoader(C_W.class, B_W.class); ByteBuffer b = s.serialize((Serializable) loaderW.loadClass(newClassName(C_W.class)).newInstance()); pushTccl(createClassNameRewritingLoader(C_R.class, B_R.class, A_R.class)); try { Object out = s.read(b); Assert.assertTrue(out.getClass().getField("called").getBoolean(out)); } finally { popTccl(); } }