List of usage examples for java.lang.reflect Field getLong
@CallerSensitive @ForceInline public long getLong(Object obj) throws IllegalArgumentException, IllegalAccessException
From source file:org.apache.hadoop.hbase.regionserver.wal.SequenceFileLogReader.java
protected IOException addFileInfoToException(final IOException ioe) throws IOException { long pos = -1; try {/*w ww.j ava 2 s . c om*/ pos = getPosition(); } catch (IOException e) { LOG.warn("Failed getting position to add to throw", e); } // See what SequenceFile.Reader thinks is the end of the file long end = Long.MAX_VALUE; try { Field fEnd = SequenceFile.Reader.class.getDeclaredField("end"); fEnd.setAccessible(true); end = fEnd.getLong(this.reader); } catch (NoSuchFieldException nfe) { /* reflection failure, keep going */ } catch (IllegalAccessException iae) { /* reflection failure, keep going */ } catch (Exception e) { /* All other cases. Should we handle it more aggressively? */ LOG.warn("Unexpected exception when accessing the end field", e); } String msg = (this.path == null ? "" : this.path.toString()) + ", entryStart=" + entryStart + ", pos=" + pos + ((end == Long.MAX_VALUE) ? "" : ", end=" + end) + ", edit=" + this.edit; // Enhance via reflection so we don't change the original class type try { return (IOException) ioe.getClass().getConstructor(String.class).newInstance(msg).initCause(ioe); } catch (NoSuchMethodException nfe) { /* reflection failure, keep going */ } catch (IllegalAccessException iae) { /* reflection failure, keep going */ } catch (Exception e) { /* All other cases. Should we handle it more aggressively? */ LOG.warn("Unexpected exception when accessing the end field", e); } return ioe; }
From source file:com.netflix.genie.agent.execution.services.impl.LaunchJobServiceImpl.java
private long getPid(final Process process) { long pid = -1; final String processClassName = process.getClass().getCanonicalName(); try {// w w w .j a va 2 s. co m if ("java.lang.UNIXProcess".equals(processClassName)) { final Field pidMemberField = process.getClass().getDeclaredField("pid"); final boolean resetAccessible = pidMemberField.isAccessible(); pidMemberField.setAccessible(true); pid = pidMemberField.getLong(process); pidMemberField.setAccessible(resetAccessible); } else { log.debug("Don't know how to access PID for class {}", processClassName); } } catch (final Throwable t) { log.warn("Failed to determine job process PID"); } return pid; }
From source file:org.apache.flink.runtime.testutils.TestJvmProcess.java
/** * Gets the process ID, if possible. This method currently only work on UNIX-based * operating systems. On others, it returns {@code -1}. * /*from w ww .ja v a 2 s . c om*/ * @return The process ID, or -1, if the ID cannot be determined. */ public long getProcessId() { checkState(process != null, "process not started"); try { Class<? extends Process> clazz = process.getClass(); if (clazz.getName().equals("java.lang.UNIXProcess")) { Field pidField = clazz.getDeclaredField("pid"); pidField.setAccessible(true); return pidField.getLong(process); } else { return -1; } } catch (Throwable ignored) { return -1; } }
From source file:org.evosuite.regression.ObjectFields.java
private static Object getFieldValue(Field field, Object p) { try {/*from w ww . j av a 2 s.c o m*/ /*Class objClass = p.getClass(); if(p instanceof java.lang.String){ ((String) p).hashCode(); }*/ Class<?> fieldType = field.getType(); field.setAccessible(true); if (fieldType.isPrimitive()) { if (fieldType.equals(Boolean.TYPE)) { return field.getBoolean(p); } if (fieldType.equals(Integer.TYPE)) { return field.getInt(p); } if (fieldType.equals(Byte.TYPE)) { return field.getByte(p); } if (fieldType.equals(Short.TYPE)) { return field.getShort(p); } if (fieldType.equals(Long.TYPE)) { return field.getLong(p); } if (fieldType.equals(Double.TYPE)) { return field.getDouble(p); } if (fieldType.equals(Float.TYPE)) { return field.getFloat(p); } if (fieldType.equals(Character.TYPE)) { return field.getChar(p); } throw new UnsupportedOperationException("Primitive type " + fieldType + " not implemented!"); } return field.get(p); } catch (IllegalAccessException exc) { throw new RuntimeException(exc); } catch (OutOfMemoryError e) { e.printStackTrace(); if (MAX_RECURSION != 0) MAX_RECURSION = 0; else throw new RuntimeErrorException(e); return getFieldValue(field, p); } }
From source file:net.pms.service.ProcessManager.java
/** * Retrieves the process ID (PID) for the specified {@link Process}. * * @param process the {@link Process} for whose PID to retrieve. * @return The PID or zero if the PID couldn't be retrieved. *//*from w w w. jav a 2 s. c om*/ public static int getProcessId(@Nullable Process process) { if (process == null) { return 0; } try { Field field; if (Platform.isWindows()) { field = process.getClass().getDeclaredField("handle"); field.setAccessible(true); int pid = Kernel32.INSTANCE.GetProcessId(new HANDLE(new Pointer(field.getLong(process)))); if (pid == 0 && LOGGER.isDebugEnabled()) { int lastError = Kernel32.INSTANCE.GetLastError(); LOGGER.debug("KERNEL32.getProcessId() failed with error {}", lastError); } return pid; } field = process.getClass().getDeclaredField("pid"); field.setAccessible(true); return field.getInt(process); } catch (Exception e) { LOGGER.warn("Failed to get process id for process \"{}\": {}", process, e.getMessage()); LOGGER.trace("", e); return 0; } }
From source file:org.jcurl.core.io.JDKSerializerTest.java
public void testSerialVersionUID() { final String[][] ser1 = { { "org.jcurl.math.Distance2DSq", "0" }, { "org.jcurl.math.R1R1Function", "0" }, { "org.jcurl.math.R1RNFunctionImpl", "0" }, { "org.jcurl.math.R1RNFunction", "0" }, { "org.jcurl.math.CurveCombined$Part", "0" }, { "org.jcurl.math.CurveCombined", "0" }, { "org.jcurl.math.BisectionSolver", "0" }, { "org.jcurl.math.Polynome", "0" }, { "org.jcurl.math.CurveFkt", "0" }, { "org.jcurl.math.CSplineInterpolator", "0" }, { "org.jcurl.math.MathVec", "0" }, { "org.jcurl.math.NewtonSimpleSolver", "0" }, { "org.jcurl.math.PolynomeCurve", "0" }, { "org.jcurl.math.CurveShape", "0" }, { "org.jcurl.core.helpers.FilterIterator", "0" }, { "org.jcurl.core.helpers.MergedIterator$1", "0" }, { "org.jcurl.core.helpers.MergedIterator$2", "0" }, { "org.jcurl.core.helpers.MergedIterator", "0" }, { "org.jcurl.core.helpers.PeekIterator", "0" }, { "org.jcurl.core.helpers.PropModelHelper", "0" }, { "org.jcurl.core.helpers.AnnoHelper", "0" }, { "org.jcurl.core.helpers.Version", "0" }, { "org.jcurl.core.helpers.NotImplementedYetException", "0" }, { "org.jcurl.core.helpers.Service", "0" }, { "org.jcurl.core.api.RockType$Acc", "0" }, { "org.jcurl.core.api.RockType$Pos", "0" }, { "org.jcurl.core.api.RockType$Vel", "0" }, { "org.jcurl.core.api.RockType", "0" }, { "org.jcurl.core.api.PropModel", "0" }, { "org.jcurl.core.api.Measure", "0" }, { "org.jcurl.core.api.Collider", "0" }, { "org.jcurl.core.api.Strategy", "0" }, { "org.jcurl.core.api.Rock$ImmutableRock", "0" }, { "org.jcurl.core.api.Rock$RockPoint", "0" }, { "org.jcurl.core.api.Rock$1", "0" }, { "org.jcurl.core.api.Rock", "0" }, { "org.jcurl.core.api.IChangeSupport", "0" }, { "org.jcurl.core.api.RockSet$1", "0" }, { "org.jcurl.core.api.RockSet", "0" }, { "org.jcurl.core.api.ChangeSupport", "0" }, { "org.jcurl.core.api.Unit", "0" }, { "org.jcurl.core.api.EnumBase$HashCodeComp", "0" }, { "org.jcurl.core.api.EnumBase$1", "0" }, { "org.jcurl.core.api.EnumBase", "0" }, { "org.jcurl.core.api.CollissionDetector", "0" }, { "org.jcurl.core.api.MutableObject", "0" }, { "org.jcurl.core.api.TransferObject", "0" }, { "org.jcurl.core.api.IPropertyChangeSupport", "0" }, { "org.jcurl.core.api.PropertyChangeSupport", "0" }, { "org.jcurl.core.api.CurveRock", "0" }, { "org.jcurl.core.api.RockSetProps", "0" }, { "org.jcurl.core.api.RockProps", "0" }, { "org.jcurl.core.api.StopDetector", "0" }, { "org.jcurl.core.api.ComputedTrajectorySet", "0" }, { "org.jcurl.core.api.TrajectorySet", "0" }, { "org.jcurl.core.api.Curler", "0" }, { "org.jcurl.core.api.Factory", "0" }, { "org.jcurl.core.api.CurveStore", "0" }, { "org.jcurl.core.api.PositionSet", "0" }, { "org.jcurl.core.api.WeakHashSet", "0" }, { "org.jcurl.core.api.Physics", "0" }, { "org.jcurl.core.api.IceSize", "0" }, { "org.jcurl.core.api.RockDouble", "0" }, { "org.jcurl.core.impl.CollissionSpinLoss", "0" }, { "org.jcurl.core.impl.ColliderBase", "0" }, { "org.jcurl.core.impl.PropModelImpl", "0" }, { "org.jcurl.core.impl.NewtonCollissionDetector", "0" }, { "org.jcurl.core.impl.CollissionDetectorBase", "0" }, { "org.jcurl.core.impl.CurveRockAnalytic", "0" }, { "org.jcurl.core.impl.NewtonStopDetector", "0" }, { "org.jcurl.core.impl.CollissionStore$Tupel", "0" }, { "org.jcurl.core.impl.CollissionStore$TupelComp", "0" }, { "org.jcurl.core.impl.CollissionStore", "0" }, { "org.jcurl.core.impl.CurveManager", "0" }, { "org.jcurl.core.impl.CurveTransformed", "0" }, { "org.jcurl.core.impl.CoulombCurler", "0" }, { "org.jcurl.core.impl.CurlerBase$1", "0" }, { "org.jcurl.core.impl.CurlerBase$2", "0" }, { "org.jcurl.core.impl.CurlerBase", "0" }, { "org.jcurl.core.impl.CollissionSimple", "0" }, { "org.jcurl.core.impl.CurlerNoCurl", "0" }, { "org.jcurl.core.impl.StoredTrajectorySet", "0" }, { "org.jcurl.core.impl.CurveStoreImpl$1", "0" }, { "org.jcurl.core.impl.CurveStoreImpl", "0" }, { "org.jcurl.core.impl.CollissionSpin", "0" }, { "org.jcurl.core.impl.CurlerDenny$1", "0" }, { "org.jcurl.core.impl.CurlerDenny", "0" }, { "org.jcurl.core.impl.CurveStill", "0" }, { "org.jcurl.core.ui.Orientation", "0" }, { "org.jcurl.core.ui.Zoomer", "0" }, { "org.jcurl.core.ui.TaskExecutor$Current", "0" }, { "org.jcurl.core.ui.TaskExecutor$ExecutorDelegate", "0" }, { "org.jcurl.core.ui.TaskExecutor$ForkableFixed", "0" }, { "org.jcurl.core.ui.TaskExecutor$ForkableFlex", "0" }, { "org.jcurl.core.ui.TaskExecutor$Parallel", "0" }, { "org.jcurl.core.ui.TaskExecutor$Single", "0" }, { "org.jcurl.core.ui.TaskExecutor$SmartQueue", "0" }, { "org.jcurl.core.ui.TaskExecutor$SwingEDT", "0" }, { "org.jcurl.core.ui.TaskExecutor$Task", "0" }, { "org.jcurl.core.ui.TaskExecutor", "0" }, { "org.jcurl.core.ui.FixpointZoomer", "0" }, { "org.jcurl.core.ui.UndoRedoDocumentBase", "0" }, { "org.jcurl.core.ui.UndoRedoDocument", "0" }, { "org.jcurl.core.ui.BroomPromptModel", "0" }, { "org.jcurl.core.io.JCurlSerializer$Engine", "0" }, { "org.jcurl.core.io.JCurlSerializer", "0" }, { "org.jcurl.core.io.IONode", "0" }, { "org.jcurl.core.io.IOTrajectories", "0" }, { "org.jcurl.core.io.IOGroup", "0" }, { "org.jcurl.core.io.JDKSerializer", "0" }, { "org.jcurl.core.log.JCLoggerFactory", "0" }, { "org.jcurl.core.jnlp.FileDialogService$Contents", "0" }, { "org.jcurl.core.jnlp.FileDialogService$ContentsBuffer", "0" }, { "org.jcurl.core.jnlp.FileDialogService$ContentsFile", "0" }, { "org.jcurl.core.jnlp.FileDialogService$OpenService", "0" }, { "org.jcurl.core.jnlp.FileDialogService$SaveService", "0" }, { "org.jcurl.core.jnlp.FileDialogService", "0" }, { "org.jcurl.core.jnlp.FileDialogWebstart$1", "0" }, { "org.jcurl.core.jnlp.FileDialogWebstart", "0" }, { "org.jcurl.core.jnlp.FileDialogSwing$1", "0" }, { "org.jcurl.core.jnlp.FileDialogSwing", "0" } }; final Object[][] ser = { { Collider.class, null }, { CollissionDetector.class, null }, { Curler.class, null }, { EnumBase.class, -5618394067421447401L }, { EnumBase.class.getName() + "$HashCodeComp", null }, { Measure.class, -958212044733309378L }, { MutableObject.class, null }, { Rock.class, null }, { Rock.class.getName() + "$ImmutableRock", null }, { Rock.class.getName() + "$RockPoint", null }, { RockDouble.class, 2337028316325540776L }, { RockSet.class, -7154547850436886952L }, { TransferObject.class, null }, { Unit.class, 6779663806431722367L }, { ColliderBase.class, -2347150866540703237L }, { CollissionDetectorBase.class, null }, { CollissionSpin.class, 8103077481042211458L }, { CoulombCurler.class, 4753259656811782206L }, { CurlerBase.class, -3873001715024033329L }, { CurlerDenny.class, 9048729754646886751L }, { CurveManager.class, 7198540442889130378L }, { NewtonCollissionDetector.class, -3370270087945653006L }, { PropModelImpl.class, -1281395608873589552L }, { IONode.class, -4734020637823903908L }, { IOTrajectories.class, -8243459215398281867L } }; for (final Object[] elem : ser) try {//from www . ja v a2 s. co m final Class<?> c = elem[0] instanceof String ? Class.forName((String) elem[0]) : (Class<?>) elem[0]; try { if (elem[1] == null) { if (Serializable.class.isAssignableFrom(c)) log.warn(c.getName() + " shouldn't be Serializable"); try { if (c.getDeclaredField("serialVersionUID") != null) log.error(c.getName() + " shouldn't have a serialVersionUID"); } catch (final NoSuchFieldException e) { } } else { final Field f = c.getDeclaredField("serialVersionUID"); f.setAccessible(true); assertEquals(c.getName(), elem[1], f.getLong(null)); } } catch (final SecurityException e) { throw new AssertionException(c.getName(), null, e); } catch (final NoSuchFieldException e) { throw new AssertionException(c.getName(), null, e); } catch (final IllegalArgumentException e) { throw new AssertionException(c.getName(), null, e); } catch (final IllegalAccessException e) { throw new AssertionException(c.getName(), null, e); } } catch (final ClassNotFoundException e) { throw new AssertionException((String) elem[0], null, e); } }
From source file:net.larry1123.elec.util.test.config.AbstractConfigTest.java
public void longTest(String fieldName, Field testField) { try {//from w ww .ja v a 2 s . c o m Assert.assertTrue(getPropertiesFile().getLong(fieldName) == testField.getLong(getConfigBase())); } catch (IllegalAccessException e) { assertFailFieldError(fieldName); } }
From source file:org.eclipse.wb.internal.xwt.model.property.editor.style.StylePropertyEditor.java
private void configureSet(List<SubStylePropertyImpl> properties, EditorContext context, Map<String, Object> parameters) throws Exception { if (parameters.containsKey("set")) { String[] setters = StringUtils.split((String) parameters.get("set")); // loop of all set's for (int i = 0; i < setters.length; i++) { // prepare flag name String[] names = StringUtils.split(setters[i], ':'); String flagName = names[0]; // prepare flag value Field field = getField(context, m_class, flagName); if (field == null) { continue; }/*from w ww. j a va 2 s . c om*/ long flag = field.getLong(null); // add property SubStylePropertyImpl property; if (names.length == 2) { property = new BooleanStylePropertyImpl(this, names[1], flagName, flag); } else { property = new BooleanStylePropertyImpl(this, flagName.toLowerCase(), flagName, flag); } properties.add(property); m_otherProperties.add(property); } } }
From source file:org.eclipse.wb.internal.core.model.property.editor.style.StylePropertyEditor.java
private void configureSet(List<SubStylePropertyImpl> properties, EditorState state, Map<String, Object> parameters) throws Exception { if (parameters.containsKey("set")) { String[] setters = StringUtils.split((String) parameters.get("set")); // loop of all set's for (int i = 0; i < setters.length; i++) { // prepare flag name String[] names = StringUtils.split(setters[i], ':'); String flagName = names[0]; // prepare flag value Field field = getField(state, m_class, flagName); if (field == null) { continue; }//w w w. j a va 2 s . c om long flag = field.getLong(null); // add property SubStylePropertyImpl property; if (names.length == 2) { property = new BooleanStylePropertyImpl(this, names[1], flagName, flag); } else { property = new BooleanStylePropertyImpl(this, flagName.toLowerCase(), flagName, flag); } properties.add(property); m_otherProperties.add(property); } } }
From source file:org.eclipse.wb.internal.core.model.property.editor.style.StylePropertyEditor.java
private void configureSetUsingEquals(List<SubStylePropertyImpl> properties, EditorState state, Map<String, Object> parameters) throws Exception { if (parameters.containsKey("setUsingEqual")) { String[] setters = StringUtils.split((String) parameters.get("setUsingEqual")); // loop of all set's for (int i = 0; i < setters.length; i++) { // prepare flag name String[] names = StringUtils.split(setters[i], ':'); String flagName = names[0]; // prepare flag value Field field = getField(state, m_class, flagName); if (field == null) { continue; }/*ww w .j a v a 2 s .c om*/ long flag = field.getLong(null); // add property SubStylePropertyImpl property; if (names.length == 2) { property = new BooleanUsingEqualsStylePropertyImpl(this, names[1], flagName, flag, m_className); } else { property = new BooleanUsingEqualsStylePropertyImpl(this, flagName.toLowerCase(), flagName, flag, m_className); } properties.add(property); m_otherProperties.add(property); } } }