public static Method findDeclaredMethod(final Class type, final String methodName, final Class[] parameterTypes) throws NoSuchMethodException { Class cl = type; while (cl != null) { try { return cl.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { cl = cl.getSuperclass(); } } throw new NoSuchMethodException(methodName); }
public Constructor<T> run() { try { return clazz.getDeclaredConstructor(paramTypes); } catch (NoSuchMethodException e) { throw new NoSuchMethodError(e.getMessage()); } }
private static Method getEquals() { if (equalsMth == null) { try { equalsMth = Object.class.getMethod("equals", Object.class); // NOI18N } catch (NoSuchMethodException e) { e.printStackTrace(); } } return equalsMth; }
@Override public final NoSuchMethodException noSuchMethod(final String name) { final NoSuchMethodException result = new NoSuchMethodException(String.format(getLoggingLocale(), noSuchMethod$str(), name)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String noSuchField = "WFLYJCA0075: Field %s not found";
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); try { method = ((MethodSerializationWrapper) stream.readObject()).getMethod(); } catch (NoSuchMethodException e) { // ///CLOVER:OFF throw new IOException(e.toString()); // ///CLOVER:ON } }
@Override public final NoSuchMethodException noSuchField(final String name) { final NoSuchMethodException result = new NoSuchMethodException(String.format(getLoggingLocale(), noSuchField$str(), name)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String noPropertyResolution = "WFLYJCA0076: Unknown property resolution for property %s";
/** * Invokes HtmlAdapterServer.start() using reflection. * * @since 1.2.16 * @param server instance of com.sun.jdmk.comm.HtmlAdapterServer. */ private static void startServer(final Object server) { try { server.getClass().getMethod("start", new Class[0]). invoke(server, new Object[0]); } catch(InvocationTargetException ex) { Throwable cause = ex.getTargetException(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause != null) { if (cause instanceof InterruptedException || cause instanceof InterruptedIOException) { Thread.currentThread().interrupt(); } throw new RuntimeException(cause.toString()); } else { throw new RuntimeException(); } } catch(NoSuchMethodException ex) { throw new RuntimeException(ex.toString()); } catch(IllegalAccessException ex) { throw new RuntimeException(ex.toString()); } }
@SuppressWarnings("unchecked") public static <T> T invoke(Method method, Object obj, Object... args) throws NoSuchMethodException { if (method == null) { throw new NoSuchMethodException(); } try { return (T) method.invoke(obj, args); } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) { // fall through } throw new NoSuchMethodException(method.getName()); } }
public Constructor<OptionalDataException> run() { try { final Constructor<OptionalDataException> constructor = OptionalDataException.class.getDeclaredConstructor(boolean.class); constructor.setAccessible(true); return constructor; } catch (NoSuchMethodException e) { throw new NoSuchMethodError(e.getMessage()); } } });
private static Method getCreatePathFromPathDataMethod() { try { return Class.forName("android.util.PathParser") .getDeclaredMethod("createPathFromPathData", String.class); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } return null; } }
@SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); Set<MethodSerializationWrapper> methods = (Set<MethodSerializationWrapper>) stream .readObject(); if (methods == null) { return; } mockedMethods = new HashSet<>(methods.size()); for (MethodSerializationWrapper m : methods) { try { mockedMethods.add(m.getMethod()); } catch (NoSuchMethodException e) { // ///CLOVER:OFF throw new IOException(e.toString()); // ///CLOVER:ON } } }
public static Method findDeclaredMethod(final Class type, final String methodName, final Class[] parameterTypes) throws NoSuchMethodException { Class cl = type; while (cl != null) { try { return cl.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { cl = cl.getSuperclass(); } } throw new NoSuchMethodException(methodName); }
/** * Creates a {@code Supplier} that will return a new instance of {@code type} each time * it's called. * * @param type The type to create * @return The supplier that will create instances * @throws IllegalArgumentException if {@code type} does not have a zero-args constructor */ public static <T> Supplier<T> supplier(final Class<T> type) { try { final Constructor<T> ctor = type.getConstructor(); return new Supplier<T>() { @Override public T get() { try { return ctor.newInstance(); } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } } }; } catch (NoSuchMethodException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
private boolean isMethodOverridden(CallableSystemAction d, String name) { try { java.lang.reflect.Method m = d.getClass().getMethod(name, new Class[0]); return m.getDeclaringClass() != CallableSystemAction.class; } catch (java.lang.NoSuchMethodException ex) { ex.printStackTrace(); throw new IllegalStateException("Error searching for method " + name + " in " + d); // NOI18N } }
protected void readMethod(DataInput in) throws Exception { if(in.readByte() == 1) { Class[] parametertypes=Util.objectFromStream(in); Class declaringclass=Util.objectFromStream(in); try { method=declaringclass.getDeclaredMethod(method_name, parametertypes); } catch(NoSuchMethodException e) { throw new IOException(e.toString()); } } }
protected void checkMethod(Method member) throws NoSuchMethodException { if ((member.getModifiers() & Modifier.PRIVATE) == Modifier.PRIVATE) { throw new NoSuchMethodException("Only public, protected and package members allowed"); } }
public FastMethod getMethod(String name, Class[] parameterTypes) { try { return getMethod(type.getMethod(name, parameterTypes)); } catch (NoSuchMethodException e) { throw new NoSuchMethodError(e.getMessage()); } }
static HashMap<String, Method> constructFactory() { HashMap<String, Method> factory = new HashMap<String, Method>(); try { factory.put("binary", BinaryOutputArchive.class.getDeclaredMethod( "getArchive", new Class[]{ OutputStream.class })); factory.put("csv", CsvOutputArchive.class.getDeclaredMethod( "getArchive", new Class[]{ OutputStream.class })); factory.put("xml", XmlOutputArchive.class.getDeclaredMethod( "getArchive", new Class[]{ OutputStream.class })); } catch (SecurityException ex) { ex.printStackTrace(); } catch (NoSuchMethodException ex) { ex.printStackTrace(); } return factory; }
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); try { toStringMethod = ((MethodSerializationWrapper) stream.readObject()).getMethod(); equalsMethod = ((MethodSerializationWrapper) stream.readObject()).getMethod(); hashCodeMethod = ((MethodSerializationWrapper) stream.readObject()).getMethod(); finalizeMethod = ((MethodSerializationWrapper) stream.readObject()).getMethod(); } catch (NoSuchMethodException e) { // ///CLOVER:OFF throw new IOException(e.toString()); // ///CLOVER:ON } }
private List<Method> getMethods(String name, int paramCount) throws NoSuchMethodException { Map<Integer, List<Method>> overloads = map.get(name); if (overloads == null) { throw new NoSuchMethodException(name); } List<Method> methods = overloads.get(paramCount); if (methods == null || methods.isEmpty()) { throw new NoSuchMethodException(name); } return methods; }