 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
danwichs@gmail.com Guest
|
Posted: Mon Mar 26, 2007 3:00 am Post subject: modifying java.lang.String.java |
|
|
Hi,
I'm trying to modify java.lang.String.java and add the modified
String.class to
rt.jar [THIS IS FOR MYSELF ONLY AND WILL NOT BE DEPLOYED].
I cannot add "private final boolean tainted[] = new
boolean[5];" to String.java. If I do, it still compiles and I can add
it to rt.jar and compile a test program against it. However, the JVM
crashes with a strange message:
java.lang.IllegalArgumentException: name can't be empty
at java.security.BasicPermission.init(Unknown Source)
at java.security.BasicPermission.<init>(Unknown Source)
at java.lang.RuntimePermission.<init>(Unknown Source)
at java.lang.Thread.<clinit>(Unknown Source)
I tried various ways of rewriting the above such as adding "private
final boolean tainted[];" and initializing it in each constructor.
Nothing works.
I can add methods to String.java and even the member variable "private
boolean isTainted;" and it works just fine. Do you have any ideas for
why adding a boolean array does not work (or better yet how to get
around this issue)?
Thank you,
Daniel |
|
| Back to top |
|
 |
Ralf Ullrich Guest
|
Posted: Mon Mar 26, 2007 3:00 am Post subject: Re: modifying java.lang.String.java |
|
|
danwichs (AT) gmail (DOT) com wrote:
| Quote: | I'm trying to modify java.lang.String.java and add the modified
String.class to
rt.jar [THIS IS FOR MYSELF ONLY AND WILL NOT BE DEPLOYED].
|
Try running the VM with
-Xshare:off
If this works re-create the shared archives
(JAVA_HOME/bin/(client|server)/classes.jsa).
HTH
cu |
|
| Back to top |
|
 |
Ralf Ullrich Guest
|
Posted: Mon Mar 26, 2007 3:00 am Post subject: Re: modifying java.lang.String.java |
|
|
danwichs (AT) gmail (DOT) com wrote:
| Quote: | On Mar 25, 7:06 pm, "Ralf Ullrich" <n...@jnana.de> wrote:
danwi...@gmail.com wrote:
I'm trying to modify java.lang.String.java and add the modified
String.class to
rt.jar [THIS IS FOR MYSELF ONLY AND WILL NOT BE DEPLOYED].
Try running the VM with
-Xshare:off
If this works re-create the shared archives
(JAVA_HOME/bin/(client|server)/classes.jsa).
HTH
cu
That still does not work. I get the same error.
|
Well, the offending code seems to be this line in java.lang.Thread:
private static final RuntimePermission
SUBCLASS_IMPLEMENTATION_PERMISSION =
new RuntimePermission("enableContextClassLoaderOverride");
where "new RuntimePermission(...)" results in your observed error if the
supplied string returns 0 for length().
So I would assume, that after you modified java.lang.String the magic
trickery within the VM that creates String objects from String literals in
class files is broken with regard to your modified String class.
I'd try to look there for the problem.
Sorry, that I cannot be of more help.
cu |
|
| Back to top |
|
 |
danwichs@gmail.com Guest
|
Posted: Mon Mar 26, 2007 5:58 am Post subject: Re: modifying java.lang.String.java |
|
|
On Mar 25, 7:06 pm, "Ralf Ullrich" <n...@jnana.de> wrote:
| Quote: | danwi...@gmail.com wrote:
I'm trying to modify java.lang.String.java and add the modified
String.class to
rt.jar [THIS IS FOR MYSELF ONLY AND WILL NOT BE DEPLOYED].
Try running the VM with
-Xshare:off
If this works re-create the shared archives
(JAVA_HOME/bin/(client|server)/classes.jsa).
HTH
cu
|
That still does not work. I get the same error. |
|
| Back to top |
|
 |
danwichs@gmail.com Guest
|
Posted: Mon Mar 26, 2007 6:34 am Post subject: Re: modifying java.lang.String.java |
|
|
Thanks. I suspect you are right. I just wish that I knew exactly what
the problem is. Unfortunatley since the error happens as the JVM is
loading, I cannot attach a debugger.
It is strange that adding "private final boolean tainted[] = new
boolean[5];"
causes a crash bud adding:
"private final boolean tainted=false;" works fine.
If anyone knows more about the internals of how the JVM makes strings
out of string literals I would appreciate a lesson.
On Mar 25, 9:21 pm, "Ralf Ullrich" <n...@jnana.de> wrote:
| Quote: | danwi...@gmail.com wrote:
On Mar 25, 7:06 pm, "Ralf Ullrich" <n...@jnana.de> wrote:
danwi...@gmail.com wrote:
I'm trying to modify java.lang.String.java and add the modified
String.class to
rt.jar [THIS IS FOR MYSELF ONLY AND WILL NOT BE DEPLOYED].
Try running the VM with
-Xshare:off
If this works re-create the shared archives
(JAVA_HOME/bin/(client|server)/classes.jsa).
HTH
cu
That still does not work. I get the same error.
Well, the offending code seems to be this line in java.lang.Thread:
private static final RuntimePermission
SUBCLASS_IMPLEMENTATION_PERMISSION =
new RuntimePermission("enableContextClassLoaderOverride");
where "new RuntimePermission(...)" results in your observed error if the
supplied string returns 0 for length().
So I would assume, that after you modified java.lang.String the magic
trickery within the VM that creates String objects from String literals in
class files is broken with regard to your modified String class.
I'd try to look there for the problem.
Sorry, that I cannot be of more help.
cu- Hide quoted text -
- Show quoted text - |
|
|
| Back to top |
|
 |
danwichs@gmail.com Guest
|
Posted: Mon Mar 26, 2007 7:10 am Post subject: Re: modifying java.lang.String.java |
|
|
I think the error is caused by the intern() function in String.java.
This is implemented in native code. I bet it somehow messes up.
On Mar 25, 9:34 pm, "danwi...@gmail.com" <danwi...@gmail.com> wrote:
| Quote: | Thanks. I suspect you are right. I just wish that I knew exactly what
the problem is. Unfortunatley since the error happens as the JVM is
loading, I cannot attach a debugger.
It is strange that adding "private final boolean tainted[] = new
boolean[5];"
causes a crash bud adding:
"private final boolean tainted=false;" works fine.
If anyone knows more about the internals of how the JVM makes strings
out of string literals I would appreciate a lesson.
On Mar 25, 9:21 pm, "Ralf Ullrich" <n...@jnana.de> wrote:
danwi...@gmail.com wrote:
On Mar 25, 7:06 pm, "Ralf Ullrich" <n...@jnana.de> wrote:
danwi...@gmail.com wrote:
I'm trying to modify java.lang.String.java and add the modified
String.class to
rt.jar [THIS IS FOR MYSELF ONLY AND WILL NOT BE DEPLOYED].
Try running the VM with
-Xshare:off
If this works re-create the shared archives
(JAVA_HOME/bin/(client|server)/classes.jsa).
HTH
cu
That still does not work. I get the same error.
Well, the offending code seems to be this line in java.lang.Thread:
private static final RuntimePermission
SUBCLASS_IMPLEMENTATION_PERMISSION =
new RuntimePermission("enableContextClassLoaderOverride");
where "new RuntimePermission(...)" results in your observed error if the
supplied string returns 0 for length().
So I would assume, that after you modified java.lang.String the magic
trickery within the VM that creates String objects from String literals in
class files is broken with regard to your modified String class.
I'd try to look there for the problem.
Sorry, that I cannot be of more help.
cu- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text - |
|
|
| Back to top |
|
 |
Moritz Hammer Guest
|
Posted: Mon Mar 26, 2007 11:43 am Post subject: Re: modifying java.lang.String.java |
|
|
On Sun, 25 Mar 2007 19:10:28 -0700, danwichs (AT) gmail (DOT) com wrote:
| Quote: | I think the error is caused by the intern() function in String.java.
This is implemented in native code. I bet it somehow messes up.
Have you considered AspectJ or some other kind of bytecode |
instrumentation? I cannot predict whether it will work, but it might be
worth a try, and your project would become much more publishable.
But apart from technical realizability, I think Tom is right; your
approach should not be dependent on the ability to modify the String class.
Regards,
Moritz |
|
| Back to top |
|
 |
Tom Hawtin Guest
|
Posted: Mon Mar 26, 2007 1:30 pm Post subject: Re: modifying java.lang.String.java |
|
|
danwichs (AT) gmail (DOT) com wrote:
| Quote: | I'm trying to modify java.lang.String.java and add the modified
String.class to
rt.jar [THIS IS FOR MYSELF ONLY AND WILL NOT BE DEPLOYED].
I cannot add "private final boolean tainted[] = new
|
Wouldn't it be easier to use WeakHashMap<String,boolean[]> (or something
similar with the map value as a meaningful class type)?
| Quote: | boolean[5];" to String.java. If I do, it still compiles and I can add
it to rt.jar and compile a test program against it. However, the JVM
crashes with a strange message:
java.lang.IllegalArgumentException: name can't be empty
at java.security.BasicPermission.init(Unknown Source)
at java.security.BasicPermission.<init>(Unknown Source)
at java.lang.RuntimePermission.<init>(Unknown Source)
at java.lang.Thread.<clinit>(Unknown Source)
|
So if you look at the source, it appears that the literal string
"enableContextClassLoaderOverride" has a length of zero.
As someone else mentioned it will be in the native code loading strings
from class files. The exact details I don't know. Moving your field
after the existing fields might help. It might be that reference fields
are treated differently to primitive fields for object layout.
I suggest your approach is probably poor.
Tom Hawtin |
|
| Back to top |
|
 |
danwichs@gmail.com Guest
|
Posted: Mon Mar 26, 2007 6:49 pm Post subject: Re: modifying java.lang.String.java |
|
|
On Mar 26, 7:43 am, Moritz Hammer <newsgroup...@hammer-tour.com>
wrote:
| Quote: | On Sun, 25 Mar 2007 19:10:28 -0700, danwi...@gmail.com wrote:
I think the error is caused by the intern() function in String.java.
This is implemented in native code. I bet it somehow messes up.
Have you considered AspectJ or some other kind of bytecode
instrumentation? I cannot predict whether it will work, but it might be
worth a try, and your project would become much more publishable.
But apart from technical realizability, I think Tom is right; your
approach should not be dependent on the ability to modify the String class.
Regards,
Moritz
|
I tried instrumentation using JavaAssist and got the same problem. The
reasons for why I want to modify the string class are rather complex
so I'd rather not get into them. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|