grails – java. Lang. illegalaccesserror: attempt to access class XYZ from class ZXY
I have a Grails application. If I start it through it, it works normally
grails run-app
In the early stage, I have deployed the application to the Tomcat instance on the node without any problems However, yesterday I started preparing to produce everything and set up a stray box to deploy the whole stack A very strange thing happened suddenly:
I have a way
def checkEmail(String email)
In my registercontroller, it calls static methods
static String normalize(final String email) throws InvalidEmailAddressException
In a groovy class, it is placed under '/ SRC / groovy' in the corresponding package in my project
Whenever I call the checkemail method in the controller, I will see the following exception:
2014-04-07 20:19:20,588 [http-bio-8080-exec-6] ERROR errors.GrailsExceptionResolver - IllegalAccessError occurred when processing request: [GET] /register/checkEmail tried to access class com.getgrape.core.exception.InvalidEmailAddressException from class com.getgrape.authority.RegisterController. Stacktrace follows: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [checkEmail] of controller [com.getgrape.authority.RegisterController] caused exception: Runtime error executing action at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53) at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49) at grails.plugin.springsecurity.web.authentication.logout.MutablelogoutFilter.doFilter(MutablelogoutFilter.java:82) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Runtime error executing action ... 6 more Caused by: java.lang.reflect.InvocationTargetException ... 6 more Caused by: java.lang.IllegalAccessError: tried to access class com.getgrape.core.exception.InvalidEmailAddressException from class com.getgrape.authority.RegisterController at com.getgrape.authority.RegisterController.checkEmail(RegisterController.groovy:128) ... 6 more
Invalidemailaddressexception is as follows and placed under '/ SRC / Java' in the corresponding package in the project:
package com.getgrape.core.exception; class InvalidEmailAddressException extends Exception { private static final long serialVersionUID = 1L; InvalidEmailAddressException() { super(); } InvalidEmailAddressException(String message) { super(message); } }
I basically don't know what happened
>I checked for possible duplicate definitions of invalidemailaddressexception, but I couldn't find anything. > I tried to rename exception in case I ignored anything or it might conflict with another library, but it didn't help either. > I checked all the import statements, and they also looked good. > If I completely delete the call to the normalize method, the error disappears So, this must be something about the method, which throws an exception. > I tried to remove the static modifier from the method and call it by instantiating the object, but it made no difference. > I checked the war file to see if it contained invalidemailaddressexception and where it should be. > I tried to deploy the application to the Tomcat I just downloaded, but the problem still exists Therefore, it should not be a configuration problem. > No compiler errors
Who knows what might happen?
java version is: oracle jdk 1.7.0_51 grails: 2.3.7 running on ubuntu 12.04
War was established through "war", and I had been running "Grails clean all" before the war began
Solution
If there is no public modifier, this method is only applicable to the package of the class See http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html. This applies to non - public exception classes Constructors and methods should also be public if you want global access