[4896] in java-interest

home help back first fref pref prev next nref lref last post

class String HAS BEEN COMPLETELY AND UTTERLY BROKEN IN BETA2

daemon@ATHENA.MIT.EDU (Jonathan Payne)
Thu Jan 18 17:50:20 1996

Date: Thu, 18 Jan 1996 12:21:38 -0800
From: Jonathan Payne <jpayne@starwave.com>
Cc: java-interest@java.sun.com, jpayne@starwave.com

Class String has been seriously and completely and utterly
mind-bogglingly broken in the beta2 release.  Apparently because of some
sort of security issue (see below), all Strings now copy their
arguments.  This means that making substrings ALSO copies, rather than
making a reference to the original one.  This is incredibly inefficient.

But what's more important is it's completely and utterly not compatible
with beta1.

String has a bunch of constructors.  One of them, a very important one,
used to take a char[], an offset, and a length, and makes a String that
points into that character array.  This is now changed, and it makes a
*copy* of the character array.  This is very serious, because it's no
longer good enough to define methods which take Strings as arguments -
you also must supply the other variations of that which take char [],
int offset, int length as well.  And the real kicker, of course, is that
none of those routines has anything in common with the other, since you
can't get at the char[] of a String (which makes sense) so that you can
share the code you wrote which operates on the char [].

In beta1 it was OK to write code which operates on char [], like a text
editor buffer (gee, I wonder if anyone would want to write an editor in
Java?), and then when the user wants substrings, just use the:

	new String(yourarray, offset, length)

constructor of String.  And what was really nice was that it was
possible to write a class, say a regular expression matcher, which
operated only on Strings.  The nice thing about that is that

	(1) Strings are pervasive in Java
	(2) you can easily turn other things INTO Strings
	(3) you CAN'T turn Strings back into char[],offset,length

Therefore, this change has now made it necessary for me to double the
size of MY regexp API to support strings and char[], AND, I need to
double the implementation as well, because now I have to support
searching in char[] in addition to searching in Strings.  OR, I have to
get used to the idea of copying my 100k character buffer which contains
the file I am editing, every time I want to search for the regexp /THIS
IS VERY BROKEN!/.

Sun, please consider restoring class String to its former self.  THIS IS
A COMPLETELY INCOMPATIBLE CHANGE WITH BETA1, and I for one have written
a whole fuckload of code which depends on the sharing nature of Strings.
I will have a VERY hard time working around this mistake.

As far as the security issue is concerned, I believe it has something to
do with an important piece of code not being able to trust a String it's
handed, because if somebody else is holding onto the char [] that
created that String, then that owner can play some tricky games with it.

Well, DUH, the solution isn't to break String - it's to change the code
that can't trust the String so that that code makes a copy of the
String.

This just kills me.  I will *not* be upgrading to beta2.

-- 
Jonathan Payne			Programmer
Starwave Corporation		mailto:jpayne@starwave.com
http://www.starwave.com/	http://www.starwave.com/people/jpayne/
I believe the Java hype (but am feeling rather shaky right now ...)
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post