java.lang.reflect.Field#getBoolean ( )源码实例Demo

下面列出了java.lang.reflect.Field#getBoolean ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ranger   文件: buildks.java
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;
	
}
 
源代码2 项目: jdk1.8-source-analysis   文件: AWTEvent.java
/**
 * 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;
}
 
源代码3 项目: stash-token-auth   文件: PathMatcher.java
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);
  }
}
 
源代码4 项目: dragonwell8_jdk   文件: VMSupportsCS8.java
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");
    }
}
 
源代码5 项目: jdk-1.7-annotated   文件: AWTEvent.java
/**
 * 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;
}
 
源代码6 项目: TencentKona-8   文件: VMSupportsCS8.java
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");
    }
}
 
源代码7 项目: jdk8u_jdk   文件: AWTEvent.java
/**
 * 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;
}
 
源代码8 项目: DevUtils   文件: DevUtils.java
/**
 * 反射获取栈顶 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;
}
 
源代码9 项目: Bats   文件: BoundsChecking.java
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;
  }
}
 
源代码10 项目: ignite   文件: ClusterStateXmlPropertiesTest.java
/**
 * 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);
}
 
源代码11 项目: openjdk-jdk9   文件: UseCodebaseOnlyDefault.java
/**
 * 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);
}
 
源代码12 项目: hottub   文件: UseCodebaseOnlyDefault.java
/**
 * 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);
}
 
源代码13 项目: dubbo-hessian-lite   文件: JavaSerializer.java
@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);
}
 
源代码14 项目: joyrpc   文件: JavaSerializer.java
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);
}
 
/**
 * @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;
}
 
源代码16 项目: jdk8u60   文件: UseCodebaseOnlyDefault.java
/**
 * 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);
}
 
源代码17 项目: netbeans   文件: NavigatorHandlerTest.java
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);
    }
}
 
源代码18 项目: openjdk-jdk8u   文件: UseCodebaseOnlyDefault.java
/**
 * 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);
}
 
源代码19 项目: Hyperium   文件: MotionBlurMod.java
static boolean isFastRenderEnabled() {
    try {
        Field fastRender = GameSettings.class.getDeclaredField("ofFastRender");
        return fastRender.getBoolean(Minecraft.getMinecraft().gameSettings);
    } catch (Exception var1) {
        return false;
    }
}
 
源代码20 项目: julongchain   文件: SM2X509CertImpl.java
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;
}