Example usage for java.lang IllegalAccessException getMessage

List of usage examples for java.lang IllegalAccessException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.edmunds.autotest.AutoTestGetterSetter.java

private void validateSetter(Object bean, Method method, Field field) {
    if (method == null) {
        return;//  www .j  ava2 s.c  o m
    }

    final String errorMsg = "Failed to validate Setter: " + bean.getClass().getName() + "." + method.getName();

    final Class<?>[] params = method.getParameterTypes();
    final Class<?> fieldType = field.getType();

    assertEquals(params.length, 1, errorMsg + " - Setter must take one parameter");

    final Class<?> paramType = params[0];
    if (!isTypeSafeAssignment(paramType, fieldType, "setter", errorMsg)) {
        return;
    }

    Object value = createValue(paramType, errorMsg);
    Object defaultValue = createDefaultValue(paramType);

    try {
        field.setAccessible(true);
        method.setAccessible(true);

        method.invoke(bean, value);
        assertEquals(field.get(bean), value, errorMsg);

        method.invoke(bean, defaultValue);
        assertEquals(field.get(bean), defaultValue, errorMsg);
    } catch (IllegalAccessException e) {
        fail(errorMsg + " : " + e.getMessage());
    } catch (InvocationTargetException e) {
        fail(errorMsg + " : " + e.getMessage());
    }
}

From source file:com.edmunds.autotest.AutoTestGetterSetter.java

private void validateGetter(Object bean, Method method, Field field) {
    if (method == null) {
        return;/*  w  w w. j  a  v a2s. com*/
    }

    final String errorMsg = "Failed to validate Getter: " + bean.getClass().getName() + "." + method.getName();

    final Class<?> fieldType = field.getType();
    final Class<?> returnType = method.getReturnType();

    if (!isTypeSafeAssignment(fieldType, returnType, "getter", errorMsg)) {
        return;
    }

    Object value = createValue(fieldType, errorMsg);
    Object defaultValue = createDefaultValue(fieldType);

    try {
        field.setAccessible(true);
        method.setAccessible(true);

        field.set(bean, value);
        assertEquals(method.invoke(bean), value, errorMsg);

        field.set(bean, defaultValue);
        final Object actualValue = method.invoke(bean);

        if (defaultValue == null && actualValue != null) {
            validateDefaultingGetter(bean, method, field, actualValue);
        } else {
            assertEquals(actualValue, defaultValue, errorMsg);
        }
    } catch (IllegalAccessException e) {
        fail(errorMsg + " : " + e.getMessage());
    } catch (InvocationTargetException e) {
        fail(errorMsg + " : " + e.getMessage());
    }
}

From source file:com.espertech.esper.event.bean.EventBeanManufacturerBean.java

private void handle(IllegalAccessException ex, String methodName) {
    String message = "Unexpected exception encountered invoking setter-method '" + methodName + "' on class '"
            + beanEventType.getUnderlyingType().getName() + "' : " + ex.getMessage();
    log.error(message, ex);// w  w  w. j  a va 2  s .  c  om
}

From source file:org.gaixie.micrite.security.service.impl.AclServiceImpl.java

@SuppressWarnings("unchecked")
public Map readAclsById(ObjectIdentity[] objects, Sid[] sids) throws NotFoundException {
    final Map acls = new HashMap();
    for (ObjectIdentity object : objects) {
        // ?Object?acl
        // ?ObjectclassNameid
        String javaType = object.getJavaType().getName();
        AclClass aclClass = aclClassDAO.findByClass(javaType);
        // No need to check for nulls, as guaranteed non-null by ObjectIdentity.getIdentifier() interface contract
        String identifier = object.getIdentifier().toString();
        long id = (Long.valueOf(identifier)).longValue();
        AclObjectIdentity aclObjectIdentity = aclObjectIdentityDAO.findByObjectId(aclClass.getId(), id);
        // ?acl?aclaces
        // spring securityacl?
        if (aclObjectIdentity == null) {
            throw new NotFoundException("Could not found specified aclObjectIdentity.");
            //                AclImpl acl = new AclImpl(object, 0, 
            //                        aclAuthorizationStrategy, auditLogger, 
            //                        null, null, false, new GrantedAuthoritySid("ROLE_ADMIN"));
            //                acls.put(object, acl); 
            //                continue;
        }//from w  ww  .  j  a v  a2s  .  co  m
        AclSid aclOwnerSid = aclObjectIdentity.getAclSid();
        Sid owner;

        if (aclOwnerSid.isPrincipal()) {
            owner = new PrincipalSid(aclOwnerSid.getSid());
        } else {
            owner = new GrantedAuthoritySid(aclOwnerSid.getSid());
        }
        AclImpl acl = new AclImpl(object, aclObjectIdentity.getId(), aclAuthorizationStrategy, auditLogger,
                null, null, false, owner);
        acls.put(object, acl);

        Field acesField = FieldUtils.getField(AclImpl.class, "aces");
        List aces;

        try {
            acesField.setAccessible(true);
            aces = (List) acesField.get(acl);
        } catch (IllegalAccessException ex) {
            throw new IllegalStateException(
                    "Could not obtain AclImpl.ace field: cause[" + ex.getMessage() + "]");
        }

        List<AclEntry> aclEntrys = aclEntryDAO.findByIdentityId(aclObjectIdentity.getId());

        for (AclEntry aclEntry : aclEntrys) {
            AclSid aclSid = aclEntry.getAclSid();
            Sid recipient;
            if (aclSid.isPrincipal()) {
                recipient = new PrincipalSid(aclSid.getSid());
            } else {
                recipient = new GrantedAuthoritySid(aclSid.getSid());
            }

            int mask = aclEntry.getMask();
            Permission permission = convertMaskIntoPermission(mask);
            boolean granting = aclEntry.isGranting();
            boolean auditSuccess = aclEntry.isAuditSuccess();
            boolean auditFailure = aclEntry.isAuditFailure();

            AccessControlEntryImpl ace = new AccessControlEntryImpl(aclEntry.getId(), acl, recipient,
                    permission, granting, auditSuccess, auditFailure);

            // Add the ACE if it doesn't already exist in the ACL.aces field
            if (!aces.contains(ace)) {
                aces.add(ace);
            }
        }

    }
    return acls;
}

From source file:edu.ucsd.xmlrpc.xmlrpc.webserver.XmlRpcServlet.java

private void handleInitParameters(ServletConfig pConfig) throws ServletException {
    for (Enumeration en = pConfig.getInitParameterNames(); en.hasMoreElements();) {
        String name = (String) en.nextElement();
        String value = pConfig.getInitParameter(name);
        try {//  www .  j a  v  a  2 s. c o  m
            if (!ReflectionUtil.setProperty(this, name, value)
                    && !ReflectionUtil.setProperty(server, name, value)
                    && !ReflectionUtil.setProperty(server.getConfig(), name, value)) {
                throw new ServletException("Unknown init parameter " + name);
            }
        } catch (IllegalAccessException e) {
            throw new ServletException("Illegal access to instance of " + server.getClass().getName()
                    + " while setting property " + name + ": " + e.getMessage(), e);
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            throw new ServletException("Failed to invoke setter for property " + name + " on instance of "
                    + server.getClass().getName() + ": " + t.getMessage(), t);
        }
    }
}

From source file:com.sm.query.ObjectQueryVisitorImpl.java

@Override
public Result visitObjectField(@NotNull ObjectQueryParser.ObjectFieldContext ctx) {
    //first is object, second is field
    Pair<Object, FieldInfo> pair = findObjectId(ctx.getText(), source, classInfoMap);
    try {/*from w  w  w.j a  v a 2s  .co  m*/
        if (pair.getFirst() == null)
            return new Result(null);
        else {
            Object object = pair.getSecond().getField().get(pair.getFirst());
            return new Result(object);
        }
    } catch (IllegalAccessException e) {
        throw new ObjectIdException(e.getMessage(), e);
    }
}

From source file:org.josso.selfservices.password.PasswordManagementServiceImpl.java

public void register(String processId, String name, Object extension) {

    if (log.isDebugEnabled())
        log.debug("Registering " + name);

    PasswordManagementProcess p = this.runningProcesses.get(processId);

    Class clazz = p.getClass();//from  ww  w .j a v a2 s . co  m

    while (clazz != null) {
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {

            if (log.isDebugEnabled())
                log.debug("Checking field : " + field.getName());

            if (field.isAnnotationPresent(Extension.class)) {

                Extension ex = field.getAnnotation(Extension.class);

                if (ex.value().equals(name)) {
                    log.debug("Injecting extension : " + name);
                    try {

                        // Make field accessible ...
                        if (!field.isAccessible()) {
                            field.setAccessible(true);
                        }
                        field.set(p, extension);
                        return;
                    } catch (IllegalAccessException e) {
                        log.error(e.getMessage(), e);
                    }
                }
            }
        }
        clazz = clazz.getSuperclass();
    }

}

From source file:com.sm.query.ObjectQueryVisitorImpl.java

private Object findId(String id) {
    if (id.toLowerCase().equals(source.getClass().getSimpleName().toLowerCase()))
        return source;
    else {/*from w  w  w.  ja  va 2  s  . co  m*/
        Pair<Object, FieldInfo> pair = findObjectId(id, source, classInfoMap);
        try {
            if (pair.getFirst() == null)
                return new Result(null);
            else
                return pair.getSecond().getField().get(pair.getFirst());
        } catch (IllegalAccessException e) {
            throw new ObjectIdException(e.getMessage(), e);
        }
    }
}

From source file:org.fao.fenix.wds.web.rest.faostat.FAOSTATDownloadNotes.java

@GET
@Produces(MediaType.TEXT_HTML)//w  ww .j a  v  a  2  s . c  o  m
@Path("{domainCode}/{lang}")
public Response createTable(@PathParam("domainCode") final String domainCode,
        @PathParam("lang") final String language) {

    // Initiate the stream
    StreamingOutput stream = new StreamingOutput() {

        @Override
        public void write(OutputStream os) throws IOException, WebApplicationException {

            // compute result
            Writer writer = new BufferedWriter(new OutputStreamWriter(os));
            Gson g = new Gson();

            // Query
            String script = "SELECT html FROM Metadata_Domain_Text[M] WHERE M.lang = '" + language
                    + "' AND M.name = 'Description' AND M.domain = '" + domainCode + "' ";
            SQLBean sql = new SQLBean(script);
            DatasourceBean db = datasourcePool.getDatasource(DATASOURCE.FAOSTATPROD.name());

            // Fetch data
            JDBCIterable it = new JDBCIterable();

            try {

                // Query DB
                it.query(db, sql.getQuery());

            } catch (IllegalAccessException e) {
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'createJSON' thrown an error: " + e.getMessage()));
            } catch (InstantiationException e) {
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'createJSON' thrown an error: " + e.getMessage()));
            } catch (SQLException e) {
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'createJSON' thrown an error: " + e.getMessage()));
            } catch (ClassNotFoundException e) {
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'createJSON' thrown an error: " + e.getMessage()));
            } catch (Exception e) {
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'getDomains' thrown an error: " + e.getMessage()));
            }

            // Build the output
            StringBuilder sb = new StringBuilder();
            sb.append("[");
            while (it.hasNext())
                sb.append(g.toJson(it.next())).append(",");
            sb.deleteCharAt(sb.length() - 1);
            sb.append("]");
            writer.write(sb.toString());

            // Convert and write the output on the stream
            writer.flush();

        }

    };

    /* Stream result */
    return Response.status(200).entity(stream).build();

}

From source file:org.apache.struts.util.RequestUtils.java

/**
 * <p>Try to locate a multipart request handler for this request. First,
 * look for a mapping-specific handler stored for us under an attribute.
 * If one is not present, use the global multipart handler, if there is
 * one.</p>//  w  ww  .  jav a  2  s.c  o  m
 *
 * @param request The HTTP request for which the multipart handler should
 *                be found.
 * @return the multipart handler to use, or null if none is found.
 * @throws ServletException if any exception is thrown while attempting to
 *                          locate the multipart handler.
 */
private static MultipartRequestHandler getMultipartHandler(HttpServletRequest request) throws ServletException {
    MultipartRequestHandler multipartHandler = null;
    String multipartClass = (String) request.getAttribute(Globals.MULTIPART_KEY);

    request.removeAttribute(Globals.MULTIPART_KEY);

    // Try to initialize the mapping specific request handler
    if (multipartClass != null) {
        try {
            multipartHandler = (MultipartRequestHandler) applicationInstance(multipartClass);
        } catch (ClassNotFoundException cnfe) {
            log.error("MultipartRequestHandler class \"" + multipartClass + "\" in mapping class not found, "
                    + "defaulting to global multipart class");
        } catch (InstantiationException ie) {
            log.error(
                    "InstantiationException when instantiating " + "MultipartRequestHandler \"" + multipartClass
                            + "\", " + "defaulting to global multipart class, exception: " + ie.getMessage());
        } catch (IllegalAccessException iae) {
            log.error(
                    "IllegalAccessException when instantiating " + "MultipartRequestHandler \"" + multipartClass
                            + "\", " + "defaulting to global multipart class, exception: " + iae.getMessage());
        }

        if (multipartHandler != null) {
            return multipartHandler;
        }
    }

    ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request);

    multipartClass = moduleConfig.getControllerConfig().getMultipartClass();

    // Try to initialize the global request handler
    if (multipartClass != null) {
        try {
            multipartHandler = (MultipartRequestHandler) applicationInstance(multipartClass);
        } catch (ClassNotFoundException cnfe) {
            throw new ServletException("Cannot find multipart class \"" + multipartClass + "\"", cnfe);
        } catch (InstantiationException ie) {
            throw new ServletException(
                    "InstantiationException when instantiating " + "multipart class \"" + multipartClass + "\"",
                    ie);
        } catch (IllegalAccessException iae) {
            throw new ServletException(
                    "IllegalAccessException when instantiating " + "multipart class \"" + multipartClass + "\"",
                    iae);
        }

        if (multipartHandler != null) {
            return multipartHandler;
        }
    }

    return multipartHandler;
}