Re: The D Programming Language
Al wrote:
Niklas Matthies wrote:
<snip>
It's not as private as one might assume; with default security
settings you can access it via reflection. For example it's possible
to corrupt a String object by replacing its char[] value.
Sure, you can use reflection to do interesting things. But that's a
whole other can of worms. It isn't just restricted to private data. If
Java's reflection is anything like C# then it can be use to bypass a
whole lot of things that the "static" compiler wouldn't have allowed.
This is fine. No /basic/ language invariants have been violated.
In addition, I believe most of these things _are_ covered under the
security principals, so you could simply restrict code access if you
want to avoid them.
One other thing, when you say it's possible to "corrupt" a String
object, what does that mean, exactly? Do you mean that it is somehow
possible to corrupt the virtual machine's memory integrity? I highly
doubt that.
Good question. String is normally an immutable object, and
Java's security model counts on this. For example, you pass a
string to a function which first verifies it for correctness
(e.g.: it's a URL, and the function verifies that you, the user,
have a right to access this URL), then executes some more or
less dangerous action. Like everything else in Java, String is
passed by reference; if you could, in another thread, modify the
contents of the string after the security checks, but before the
action, you could violate security.
You might even be able to violate the memory model. String is a
very special case in Java, because it is not just a library
component; it is also part of the language. As such, the VM
"knows" that it is immutable, and could conceivably just do the
bounds check once, on entering the function, and count on the
length not changing. I don't think that this would be legal,
since I think the compiler is required to treat the String like
any other type, but I'm not sure of it.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]