Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

modifying java.lang.String.java

15 views
Skip to first unread message

danw...@gmail.com

unread,
Mar 25, 2007, 6:00:27 PM3/25/07
to
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

unread,
Mar 25, 2007, 7:06:17 PM3/25/07
to
danw...@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

danw...@gmail.com

unread,
Mar 25, 2007, 8:58:40 PM3/25/07
to
On Mar 25, 7:06 pm, "Ralf Ullrich" <n...@jnana.de> wrote:

That still does not work. I get the same error.

Ralf Ullrich

unread,
Mar 25, 2007, 9:21:15 PM3/25/07
to
danw...@gmail.com wrote:

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

danw...@gmail.com

unread,
Mar 25, 2007, 9:34:14 PM3/25/07
to
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.

> cu- Hide quoted text -
>
> - Show quoted text -


danw...@gmail.com

unread,
Mar 25, 2007, 10:10:28 PM3/25/07
to
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.

> > - Show quoted text -- Hide quoted text -

Tom Hawtin

unread,
Mar 26, 2007, 4:30:37 AM3/26/07
to
danw...@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].
> 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
> 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

Moritz Hammer

unread,
Mar 26, 2007, 7:43:56 AM3/26/07
to
On Sun, 25 Mar 2007 19:10:28 -0700, danw...@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

danw...@gmail.com

unread,
Mar 26, 2007, 9:49:45 AM3/26/07
to
On Mar 26, 7:43 am, Moritz Hammer <newsgroup...@hammer-tour.com>
wrote:

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.

0 new messages