It's not a secret anymore!*
The moose likes Servlets and the fly likes java.lang.IllegalAccessError in doGet() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "java.lang.IllegalAccessError in doGet()" Watch "java.lang.IllegalAccessError in doGet()" New topic
Author

java.lang.IllegalAccessError in doGet()

Ryan Dirmeyer
Greenhorn

Joined: Sep 26, 2001
Posts: 3
I have a servlet that accepts several HTTP parameters. Some of them are used to transmit error data.
I have another public class defined in a separate source file that implements Runnable and handles all error data logging. When I attempt to fire off a new thread using this class I get an IllegalAccessError 'try to access xxx from xxx'.
I've done a search on this topic and found one posting a while back that was never answered. Can anyone help me out?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
Here is what the SDK 1.3 API says:
-----
public class IllegalAccessError
extends IncompatibleClassChangeError
Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
---------
Does that make any sense in the context?
How exactly do you do this and what do the xxx stand for:
fire off a new thread using this class I get an IllegalAccessError 'try to access xxx from xxx'.
Ryan Dirmeyer
Greenhorn

Joined: Sep 26, 2001
Posts: 3
I guess I should have mentioned that I did read that part of the API docs before I posted the question. No, it doesn't make sense to me. A clearer explanation or a quick code snippet would help in many cases in the API docs, but enough whining...
Here is what I have, in a nutshell:
[much code has been removed for brevity]
// file: Vts20.java
public class Vts20 extends HttpServlet {
Thread errLogThread;
ErrorLog errLog;
String fileName;
doGet(req, resp) {
// set fileName, evName, and evMessage
errLog = new ErrorLog(fileName);
errLog.setLogData(evName, evMessage);
errLogThread = new Thread(errLog);
errLogThread.start();
// stuff
// more stuff
}
}
// file: ErrorLog.java
public class ErrorLog implements Runnable {
File file;
String evName, evMessage;
public ErrorLog(String fileName) {
this.file = new File(fileName);
}
public void setLogData(String evName, String evMessage) {
this.evName = evName;
this.evMessage = evMessage;
}
public void run() {
append();
}
public void append() {
// open file
// format and log data
// more stuff
}
}
The IllegalAccessError is thrown when trying to instantiate the ErrorLog object in doGet. I modified the code to run from a command program and everything works fine that way. It appears to only occur when in a servlet.
Much has been left out but hopefully I kept enough in for it to be helpful.
-Ryan
BTW - I passed the SCJP last month using your exam cram. Thanks for the help!
[ January 29, 2002: Message edited by: Ryan Dirmeyer ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
That is pretty mysterious alright. I would put in a try/catch to dump the entire stack trace - maybe that will give you a clue.
Are you saying that it never gets past the constructor? So really it never gets to the Thread part....
Bill
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I can think of a few containers that don't allow you to make your own threads (think iPlanet). ErroLog implements Runnable, so trying to create this object might throw an exception. It would normally be some sort SecurityException, but perhaps this is what is happening?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.IllegalAccessError in doGet()