Example usage for java.lang NoSuchFieldException getMessage

List of usage examples for java.lang NoSuchFieldException getMessage

Introduction

In this page you can find the example usage for java.lang NoSuchFieldException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:se.nrm.dina.data.util.Util.java

/**
 * Validates one field in an entity/*w ww .j a v  a  2 s.  c o m*/
 * @param clazz
 * @param fieldName
 * @return boolean
 */
public boolean validateFields(Class clazz, String fieldName) {
    logger.info("validateFields : {} -- {}", clazz, fieldName);
    try {
        clazz.getDeclaredField(fieldName);
        return true;
    } catch (NoSuchFieldException e) {
        Class superClass = clazz.getSuperclass();
        if (superClass == null) {
            throw new DinaException(e.getMessage());
        } else {
            return validateFields(superClass, fieldName);
        }
    }
}

From source file:org.shareok.data.redis.server.DspaceRepoServerDaoImpl.java

@Override
public RepoServer getRepoTypeServerFromAbstract(RepoServer server) {
    DspaceRepoServer dServer = RedisUtil.getDspaceRepoServerInstance();
    Field[] fields = server.getClass().getDeclaredFields();
    for (Field field : fields) {
        String key = field.getName();
        field.setAccessible(true);//from  w  ww.  j a va 2s .c o m
        Object val;
        try {
            val = field.get(server);
            if (null != val) {
                Field iField = null;
                try {
                    iField = dServer.getClass().getSuperclass().getDeclaredField(key);
                } catch (NoSuchFieldException ex) {
                    logger.debug("This field " + key + " does not exist!");
                    continue;
                } catch (SecurityException ex) {
                    logger.debug("Security exception when handles field " + key + "!");
                    continue;
                }
                iField.setAccessible(true);
                iField.set(dServer, val);
            }
        } catch (IllegalArgumentException | IllegalAccessException ex) {
            logger.error("Cannot get property values from server: " + ex.getMessage());
        }

    }
    return dServer;
}

From source file:org.shareok.data.redis.server.IslandoraRepoServerDaoImpl.java

@Override
public RepoServer getRepoTypeServerFromAbstract(RepoServer server) {
    IslandoraRepoServer iServer = RedisUtil.getIslandoraRepoServerInstance();
    Field[] fields = server.getClass().getDeclaredFields();
    for (Field field : fields) {
        String key = field.getName();
        field.setAccessible(true);/*from w  w w. j  ava  2 s  .  c om*/
        Object val;
        try {
            val = field.get(server);
            if (null != val) {
                Field iField = null;
                try {
                    iField = iServer.getClass().getSuperclass().getDeclaredField(key);
                } catch (NoSuchFieldException ex) {
                    logger.debug("This field " + key + " does not exist!");
                    continue;
                } catch (SecurityException ex) {
                    logger.debug("Security exception when handles field " + key + "!");
                    continue;
                }
                iField.setAccessible(true);
                iField.set(iServer, val);
            }
        } catch (IllegalArgumentException | IllegalAccessException ex) {
            logger.error("Cannot get property values from server: " + ex.getMessage());
        }

    }
    return iServer;
}

From source file:eu.eidas.auth.engine.metadata.MetadataGenerator.java

private Organization buildOrganization() {
    Organization organization = null;/*  www. ja  v a2s . c  o m*/
    try {
        organization = BuilderFactoryUtil.buildXmlObject(Organization.class);
        OrganizationDisplayName odn = BuilderFactoryUtil.buildXmlObject(OrganizationDisplayName.class);
        odn.setName(new LocalizedString(params.countryName, MetadataConfigParams.DEFAULT_LANG));
        organization.getDisplayNames().add(odn);
        OrganizationURL url = BuilderFactoryUtil.buildXmlObject(OrganizationURL.class);
        url.setURL(new LocalizedString(params.nodeUrl, MetadataConfigParams.DEFAULT_LANG));
        organization.getURLs().add(url);
    } catch (IllegalAccessException iae) {
        LOGGER.info("ERROR : error generating the Organization: {}", iae.getMessage());
        LOGGER.debug("ERROR : error generating the Organization: {}", iae);
    } catch (NoSuchFieldException nfe) {
        LOGGER.info("ERROR : error generating the Organization: {}", nfe.getMessage());
        LOGGER.debug("ERROR : error generating the Organization: {}", nfe);
    }
    return organization;
}

From source file:ch.cyberduck.core.ftp.FTPClient.java

@Override
protected void _prepareDataSocket_(final Socket socket) throws IOException {
    if (preferences.getBoolean("ftp.tls.session.requirereuse")) {
        if (socket instanceof SSLSocket) {
            // Control socket is SSL
            final SSLSession session = ((SSLSocket) _socket_).getSession();
            if (session.isValid()) {
                final SSLSessionContext context = session.getSessionContext();
                context.setSessionCacheSize(preferences.getInteger("ftp.ssl.session.cache.size"));
                try {
                    final Field sessionHostPortCache = context.getClass()
                            .getDeclaredField("sessionHostPortCache");
                    sessionHostPortCache.setAccessible(true);
                    final Object cache = sessionHostPortCache.get(context);
                    final Method method = cache.getClass().getDeclaredMethod("put", Object.class, Object.class);
                    method.setAccessible(true);
                    method.invoke(cache, String.format("%s:%s", socket.getInetAddress().getHostName(),
                            String.valueOf(socket.getPort())).toLowerCase(Locale.ROOT), session);
                    method.invoke(cache, String.format("%s:%s", socket.getInetAddress().getHostAddress(),
                            String.valueOf(socket.getPort())).toLowerCase(Locale.ROOT), session);
                } catch (NoSuchFieldException e) {
                    // Not running in expected JRE
                    log.warn("No field sessionHostPortCache in SSLSessionContext", e);
                } catch (Exception e) {
                    // Not running in expected JRE
                    log.warn(e.getMessage());
                }// w  w  w  .j  a  va  2 s  .c om
            } else {
                log.warn(String.format("SSL session %s for socket %s is not rejoinable", session, socket));
            }
        }
    }
}

From source file:com.datatorrent.contrib.parser.FixedWidthParser.java

/**
 * Function to add a setter for a field and add it
 * to the List of setters//from   w  w w .  j a va 2s.com
 *
 * @param fieldName name of the field for which setter is to be added
 */
private void addSetter(String fieldName) {
    try {
        Field f = clazz.getDeclaredField(fieldName);
        FixedWidthParser.TypeInfo t = new FixedWidthParser.TypeInfo(f.getName(),
                ClassUtils.primitiveToWrapper(f.getType()));
        t.setter = PojoUtils.createSetter(clazz, t.name, t.type);
        setters.add(t);
    } catch (NoSuchFieldException e) {
        throw new RuntimeException("Field " + fieldName + " not found in class " + clazz, e);
    } catch (Exception e) {
        throw new RuntimeException("Exception while adding a setter" + e.getMessage(), e);
    }
}

From source file:eu.eidas.auth.engine.metadata.MetadataGenerator.java

private ContactPerson buildContact(ContactPersonTypeEnumeration contactType) {
    ContactPerson contact = null;//from   w  ww. j av a  2s.c om
    try {
        Contact currentContact = null;
        if (contactType == ContactPersonTypeEnumeration.SUPPORT) {
            currentContact = params.getSupportContact();
        } else if (contactType == ContactPersonTypeEnumeration.TECHNICAL) {
            currentContact = params.getTechnicalContact();
        } else {
            LOGGER.error("ERROR: unsupported contact type");
        }
        contact = BuilderFactoryUtil.buildXmlObject(ContactPerson.class);
        if (currentContact == null) {
            LOGGER.error("ERROR: cannot retrieve contact from the configuration");
            return contact;
        }

        EmailAddress emailAddressObj = BuilderFactoryUtil.buildXmlObject(EmailAddress.class);
        Company company = BuilderFactoryUtil.buildXmlObject(Company.class);
        GivenName givenName = BuilderFactoryUtil.buildXmlObject(GivenName.class);
        SurName surName = BuilderFactoryUtil.buildXmlObject(SurName.class);
        TelephoneNumber phoneNumber = BuilderFactoryUtil.buildXmlObject(TelephoneNumber.class);
        contact.setType(contactType);
        emailAddressObj.setAddress(currentContact.getEmail());
        company.setName(currentContact.getCompany());
        givenName.setName(currentContact.getGivenName());
        surName.setName(currentContact.getSurName());
        phoneNumber.setNumber(currentContact.getPhone());

        populateContact(contact, currentContact, emailAddressObj, company, givenName, surName, phoneNumber);

    } catch (IllegalAccessException iae) {
        LOGGER.info("ERROR : error generating the Organization: {}", iae.getMessage());
        LOGGER.debug("ERROR : error generating the Organization: {}", iae);
    } catch (NoSuchFieldException nfe) {
        LOGGER.info("ERROR : error generating the Organization: {}", nfe.getMessage());
        LOGGER.debug("ERROR : error generating the Organization: {}", nfe);
    }
    return contact;
}

From source file:com.adf.bean.AbsBean.java

public Object getValueByColumn(String col) {
    Field f;// ww  w . j a  v a 2s .  co  m
    try {
        f = getClass().getDeclaredField(col);
        f.setAccessible(true);
        Object obj = f.get(this);
        if (obj != null) {
            return obj;
        }
    } catch (NoSuchFieldException e) {
        LogUtil.err("getValueByColumn NoSuchFieldException, col " + col + " not exist!!!");
    } catch (IllegalAccessException e) {
    } catch (IllegalArgumentException e) {
        LogUtil.err("getValueByColumn IllegalArgumentException, col " + col + " :" + e.getMessage());
        throw e;
    }
    return null;
}

From source file:org.skfiy.typhon.spi.GMConsoleProvider.java

private void initSessionThreadLocal() {
    try {//ww  w  .  j  ava2 s.  com
        Field field = SessionContext.class.getDeclaredField("LOCAL_SESSION");
        field.setAccessible(true);
        _local_session = (ThreadLocal<Session>) field.get(SessionContext.class);
    } catch (NoSuchFieldException ex) {
        throw new ComponentException("SessionContext?[LOCAL_SESSION]", ex);
    } catch (SecurityException ex) {
        throw new ComponentException(getClass() + " SessionContext [LOCAL_SESSION] ??",
                ex);
    } catch (Exception ex) {
        throw new ComponentException(ex.getMessage(), ex);
    }
}

From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java

boolean areAppNotificationsEnabledOnPlatform() {
    if (android.os.Build.VERSION.SDK_INT < ANDROID_KITKAT) {
        return true;
    }/*from   w ww . ja  v  a2 s  .  co  m*/

    final String appOpsServiceName;
    try {
        final Field appOpsServiceNameField = Context.class.getDeclaredField(APP_OPS_SERVICE);
        appOpsServiceName = (String) appOpsServiceNameField.get(String.class);
    } catch (final NoSuchFieldException e) {
        log.error(e.getMessage(), e);
        return true;
    } catch (final IllegalAccessException e) {
        log.error(e.getMessage(), e);
        return true;
    }

    final Object mAppOps = pinpointContext.getApplicationContext().getSystemService(appOpsServiceName);
    if (mAppOps == null) {
        return true;
    }

    final ApplicationInfo appInfo = pinpointContext.getApplicationContext().getApplicationInfo();
    final String pkg = pinpointContext.getApplicationContext().getPackageName();

    final int uid = appInfo.uid;

    try {
        if (appOpsClass == null || checkOpNoThrowMethod == null || opPostNotificationField == null
                || modeAllowedField == null) {
            appOpsClass = Class.forName(mAppOps.getClass().getName());
            checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE,
                    String.class);
            opPostNotificationField = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION);
            modeAllowedField = appOpsClass.getDeclaredField(APP_OPS_MODE_ALLOWED);
        }

        final int postNotificationValue = opPostNotificationField.getInt(null);
        final int opPostNotificationMode = (Integer) checkOpNoThrowMethod.invoke(mAppOps, postNotificationValue,
                uid, pkg);
        final int modeAllowed = modeAllowedField.getInt(null);
        return (modeAllowed == opPostNotificationMode);

    } catch (final ClassNotFoundException e) {
        log.error(e.getMessage(), e);
    } catch (final NoSuchMethodException e) {
        log.error(e.getMessage(), e);
    } catch (final NoSuchFieldException e) {
        log.error(e.getMessage(), e);
    } catch (final InvocationTargetException e) {
        log.error(e.getMessage(), e);
    } catch (final IllegalAccessException e) {
        log.error(e.getMessage(), e);
    }
    return true;
}