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
Ralf Ullrich - 26 Mar 2007 00:06 GMT
> 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
danwichs@gmail.com - 26 Mar 2007 01:58 GMT
> 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
>
[quoted text clipped - 4 lines]
>
> cu
That still does not work. I get the same error.
Ralf Ullrich - 26 Mar 2007 02:21 GMT
>>danwi...@gmail.com wrote:
>>> I'm trying to modify java.lang.String.java and add the modified
[quoted text clipped - 13 lines]
>
>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
danwichs@gmail.com - 26 Mar 2007 02:34 GMT
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.
> danwi...@gmail.com wrote:
> >>danwi...@gmail.com wrote:
[quoted text clipped - 35 lines]
>
> - Show quoted text -
danwichs@gmail.com - 26 Mar 2007 03:10 GMT
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:
> 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
[quoted text clipped - 51 lines]
>
> - Show quoted text -
Moritz Hammer - 26 Mar 2007 12:43 GMT
> 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
danwichs@gmail.com - 26 Mar 2007 14:49 GMT
On Mar 26, 7:43 am, Moritz Hammer <newsgroup...@hammer-tour.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.
[quoted text clipped - 8 lines]
> 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.
Tom Hawtin - 26 Mar 2007 09:30 GMT
> 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)?
> 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
[quoted text clipped - 5 lines]
> 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