Java Code Examples for java.lang.reflect.Field#getBoolean()

The following examples show how to use java.lang.reflect.Field#getBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: buildks.java    From ranger with Apache License 2.0 6 votes vote down vote up
private static boolean isCredentialShellInteractiveEnabled() {
	boolean ret = false;
	
	String fieldName = "interactive";
	
	CredentialShell cs = new CredentialShell();
	
	try {
		Field interactiveField = cs.getClass().getDeclaredField(fieldName);
		
		if (interactiveField != null) {
			interactiveField.setAccessible(true);
			ret = interactiveField.getBoolean(cs);
			System.out.println("FOUND value of [" + fieldName + "] field in the Class [" + cs.getClass().getName() + "] = [" + ret + "]");
		}
	} catch (Throwable e) {
		System.out.println("Unable to find the value of [" + fieldName + "] field in the Class [" + cs.getClass().getName() + "]. Skiping -f option");
		e.printStackTrace();
		ret = false;
	}
	
	return ret;
	
}
 
Example 2
Source File: AWTEvent.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Copies all private data from this event into that.
 * Space is allocated for the copied data that will be
 * freed when the that is finalized. Upon completion,
 * this event is not changed.
 */
void copyPrivateDataInto(AWTEvent that) {
    that.bdata = this.bdata;
    // Copy canAccessSystemClipboard value from this into that.
    if (this instanceof InputEvent && that instanceof InputEvent) {
        Field field = get_InputEvent_CanAccessSystemClipboard();
        if (field != null) {
            try {
                boolean b = field.getBoolean(this);
                field.setBoolean(that, b);
            } catch(IllegalAccessException e) {
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
                    log.fine("AWTEvent.copyPrivateDataInto() got IllegalAccessException ", e);
                }
            }
        }
    }
    that.isSystemGenerated = this.isSystemGenerated;
}
 
Example 3
Source File: PathMatcher.java    From stash-token-auth with GNU General Public License v3.0 6 votes vote down vote up
private void init(Paths p) {
  Class cls = p.getClass();
  try {
    for (Field f : cls.getDeclaredFields()) {
      Matches m = f.getAnnotation(Matches.class);
      if (m != null) {
        f.setAccessible(true);
        boolean allowed = f.getBoolean(p);
        for (String str : m.value()) {
          paths.put(Utils.createRegexFromGlob(str), new PathInfo(allowed,
              Pattern.compile(Utils.createRegexFromGlob(str))));
        }
      }
    }
  } catch (IllegalAccessException e) {
    throw new RuntimeException(e);
  }
}
 
Example 4
Source File: VMSupportsCS8.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (System.getProperty("sun.cpu.isalist").matches
        (".*\\b(sparcv9|pentium_pro|ia64|amd64).*")
        ||
        System.getProperty("os.arch").matches
        (".*\\b(ia64|amd64).*")) {

        System.out.println("This system is known to have hardware CS8");

        Class klass = Class.forName("java.util.concurrent.atomic.AtomicLong");
        Field field = klass.getDeclaredField("VM_SUPPORTS_LONG_CAS");
        field.setAccessible(true);
        boolean VMSupportsCS8 = field.getBoolean(null);
        if (! VMSupportsCS8)
            throw new Exception("Unexpected value for VMSupportsCS8");
    }
}
 
Example 5
Source File: AWTEvent.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
/**
 * Copies all private data from this event into that.
 * Space is allocated for the copied data that will be
 * freed when the that is finalized. Upon completion,
 * this event is not changed.
 */
void copyPrivateDataInto(AWTEvent that) {
    that.bdata = this.bdata;
    // Copy canAccessSystemClipboard value from this into that.
    if (this instanceof InputEvent && that instanceof InputEvent) {
        Field field = get_InputEvent_CanAccessSystemClipboard();
        if (field != null) {
            try {
                boolean b = field.getBoolean(this);
                field.setBoolean(that, b);
            } catch(IllegalAccessException e) {
                if (log.isLoggable(PlatformLogger.FINE)) {
                    log.fine("AWTEvent.copyPrivateDataInto() got IllegalAccessException ", e);
                }
            }
        }
    }
    that.isSystemGenerated = this.isSystemGenerated;
}
 
Example 6
Source File: DevUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 反射获取栈顶 Activity
 * @return {@link Activity}
 */
private Activity getTopActivityByReflect() {
    try {
        @SuppressLint("PrivateApi")
        Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
        Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null);
        Field activitiesField = activityThreadClass.getDeclaredField("mActivityLists");
        activitiesField.setAccessible(true);
        Map activities = (Map) 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);
                return (Activity) activityField.get(activityRecord);
            }
        }
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getTopActivityByReflect");
    }
    return null;
}
 
Example 7
Source File: VMSupportsCS8.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (System.getProperty("sun.cpu.isalist").matches
        (".*\\b(sparcv9|pentium_pro|ia64|amd64).*")
        ||
        System.getProperty("os.arch").matches
        (".*\\b(ia64|amd64).*")) {

        System.out.println("This system is known to have hardware CS8");

        Class klass = Class.forName("java.util.concurrent.atomic.AtomicLong");
        Field field = klass.getDeclaredField("VM_SUPPORTS_LONG_CAS");
        field.setAccessible(true);
        boolean VMSupportsCS8 = field.getBoolean(null);
        if (! VMSupportsCS8)
            throw new Exception("Unexpected value for VMSupportsCS8");
    }
}
 
Example 8
Source File: AWTEvent.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Copies all private data from this event into that.
 * Space is allocated for the copied data that will be
 * freed when the that is finalized. Upon completion,
 * this event is not changed.
 */
void copyPrivateDataInto(AWTEvent that) {
    that.bdata = this.bdata;
    // Copy canAccessSystemClipboard value from this into that.
    if (this instanceof InputEvent && that instanceof InputEvent) {
        Field field = get_InputEvent_CanAccessSystemClipboard();
        if (field != null) {
            try {
                boolean b = field.getBoolean(this);
                field.setBoolean(that, b);
            } catch(IllegalAccessException e) {
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
                    log.fine("AWTEvent.copyPrivateDataInto() got IllegalAccessException ", e);
                }
            }
        }
    }
    that.isSystemGenerated = this.isSystemGenerated;
}
 
Example 9
Source File: SM2X509CertImpl.java    From julongchain with Apache License 2.0 5 votes vote down vote up
private boolean isReadOnly() {
    try {
        Field field = X509CertImpl.class.getDeclaredField("readOnly");
        field.setAccessible(true);
        return field.getBoolean(this);
    } catch (Exception e) {
        log.warn("reflect get field readOnly failed: {}", e);
    }
    return true;
}
 
Example 10
Source File: BoundsChecking.java    From Bats with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 11
Source File: MotionBlurMod.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
static boolean isFastRenderEnabled() {
    try {
        Field fastRender = GameSettings.class.getDeclaredField("ofFastRender");
        return fastRender.getBoolean(Minecraft.getMinecraft().gameSettings);
    } catch (Exception var1) {
        return false;
    }
}
 
Example 12
Source File: UseCodebaseOnlyDefault.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the actual useCodebaseOnly value by creating an instance
 * of MarshalInputStream and reflecting on the useCodebaseOnly field.
 */
static boolean getActualValue() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject("foo");
    oos.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    MarshalInputStream mis = new MarshalInputStream(bais);

    Field f = MarshalInputStream.class.getDeclaredField("useCodebaseOnly");
    f.setAccessible(true);
    return f.getBoolean(mis);
}
 
Example 13
Source File: NavigatorHandlerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void waitForProviders(NavigatorTC navTC) throws NoSuchFieldException, SecurityException, InterruptedException, IllegalArgumentException, IllegalAccessException {
    Field field = NavigatorController.class.getDeclaredField("inUpdate");
    field.setAccessible(true);
    while (field.getBoolean(navTC.getController())) {
        Thread.sleep(100);
    }
}
 
Example 14
Source File: UseCodebaseOnlyDefault.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the actual useCodebaseOnly value by creating an instance
 * of MarshalInputStream and reflecting on the useCodebaseOnly field.
 */
static boolean getActualValue() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject("foo");
    oos.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    MarshalInputStream mis = new MarshalInputStream(bais);

    Field f = MarshalInputStream.class.getDeclaredField("useCodebaseOnly");
    f.setAccessible(true);
    return f.getBoolean(mis);
}
 
Example 15
Source File: UtilsActivityLifecycleImpl.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * @return the activities which topActivity is first position
 */
private List<Activity> getActivitiesByReflect() {
    LinkedList<Activity> list = new LinkedList<>();
    Activity topActivity = null;
    try {
        Object activityThread = getActivityThread();
        Field mActivitiesField = activityThread.getClass().getDeclaredField("mActivities");
        mActivitiesField.setAccessible(true);
        Object mActivities = mActivitiesField.get(activityThread);
        if (!(mActivities instanceof Map)) {
            return list;
        }
        Map<Object, Object> binder_activityClientRecord_map = (Map<Object, Object>) mActivities;
        for (Object activityRecord : binder_activityClientRecord_map.values()) {
            Class activityClientRecordClass = activityRecord.getClass();
            Field activityField = activityClientRecordClass.getDeclaredField("activity");
            activityField.setAccessible(true);
            Activity activity = (Activity) activityField.get(activityRecord);
            if (topActivity == null) {
                Field pausedField = activityClientRecordClass.getDeclaredField("paused");
                pausedField.setAccessible(true);
                if (!pausedField.getBoolean(activityRecord)) {
                    topActivity = activity;
                } else {
                    list.add(activity);
                }
            } else {
                list.add(activity);
            }
        }
    } catch (Exception e) {
        Log.e("UtilsActivityLifecycle", "getActivitiesByReflect: " + e.getMessage());
    }
    if (topActivity != null) {
        list.addFirst(topActivity);
    }
    return list;
}
 
Example 16
Source File: JavaSerializer.java    From joyrpc with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 17
Source File: JavaSerializer.java    From dubbo-hessian-lite with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 18
Source File: UseCodebaseOnlyDefault.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the actual useCodebaseOnly value by creating an instance
 * of MarshalInputStream and reflecting on the useCodebaseOnly field.
 */
static boolean getActualValue() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject("foo");
    oos.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    MarshalInputStream mis = new MarshalInputStream(bais);

    Field f = MarshalInputStream.class.getDeclaredField("useCodebaseOnly");
    f.setAccessible(true);
    return f.getBoolean(mis);
}
 
Example 19
Source File: UseCodebaseOnlyDefault.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the actual useCodebaseOnly value by creating an instance
 * of MarshalInputStream and reflecting on the useCodebaseOnly field.
 */
static boolean getActualValue() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject("foo");
    oos.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    MarshalInputStream mis = new MarshalInputStream(bais);

    Field f = MarshalInputStream.class.getDeclaredField("useCodebaseOnly");
    f.setAccessible(true);
    return f.getBoolean(mis);
}
 
Example 20
Source File: ClusterStateXmlPropertiesTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Gets from given config {@code cfg} field with name {@code fieldName} and type boolean.
 *
 * @param cfg Config.
 * @param fieldName Name of field.
 * @return Value of field.
 */
private boolean getBooleanFieldFromConfig(IgniteConfiguration cfg, String fieldName) throws IllegalAccessException {
    A.notNull(cfg, "cfg");
    A.notNull(fieldName, "fieldName");

    Field field = U.findField(IgniteConfiguration.class, fieldName);
    field.setAccessible(true);

    return field.getBoolean(cfg);
}