Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: CLI Java Glitch

Reply
Thread Tools

Re: CLI Java Glitch

 
 
Bent C Dalager
Guest
Posts: n/a
 
      06-24-2011
The below program creates two distinct files on the file system of my
OSX 10.6.7, one with a regular hyphen and one with the non-breaking
hyphen. Other OS/FS combinations may behave differently. Of course,
the two files look exactly the same. In my opinion this is a lot more
subtle than a case difference and just underscores that string
comparison is a very complicated topic. (This particular sort of
subtelty used to be phishing gold, but I believe browser vendors have
since implemented countermeasures against that.)

I can't offhand think of any characters that are legal in Java symbols
and that might also have similarly subtle issues.


import java.io.File;
import java.io.IOException;

public class TestCase
{
public static void main(String[] args)
throws IOException
{
File fileHyphen = new File("test-file.tmp");
File fileNbrkHyphen = new File("test\u2011file.tmp");

createFile(fileHyphen);
createFile(fileNbrkHyphen);
}

static void createFile(File file)
throws IOException
{
if (!file.createNewFile())
{
System.out.println("Could not create " + file);
}
}
}


$ javac TestCase.java
$ java TestCase
$ ls test*
test-file.tmp test‑file.tmp
$ java TestCase
Could not create test-file.tmp
Could not create test?file.tmp

(not sure what I have misconfigured that *******sed up the Unicode on
that last line)

Cheers,
Bent D
--
Bent Dalager - http://www.velocityreviews.com/forums/(E-Mail Removed) - http://www.pvv.org/~bcd
powered by emacs
 
Reply With Quote
 
 
 
 
Tom Anderson
Guest
Posts: n/a
 
      06-25-2011
On Fri, 24 Jun 2011, Esmond Pitt wrote:

> On 24/06/2011 8:20 AM, Tom Anderson wrote:
>> Oh, that's just a modern typesetting fad. It's not intrinsically uppercase.

>
> This statement doesn't really mean anything. *All* uppercase is a
> 'typesetting fad'; nothing is intrinsically uppercase. Or lowercase.


YOU KNOW YOURE QUITE RIGHT THIS MAKES MY LIFE SUBSTANTIALLY EASIER THANKS
ONCE AGAIN MR PITT

TOM

--
space, robots, pirates, vikings, ninjas, medieval castles, dinosaurs,
cities, suburbia, holiday locations, wild west, the Arctic, airports,
boats, racing cars, trains, Star Wars, Harry Potter, Spider-Man, Batman,
SpongeBob SquarePants, Avatar: The Last Airbender and more
 
Reply With Quote
 
 
 
 
Gene Wirchenko
Guest
Posts: n/a
 
      06-27-2011
On Fri, 24 Jun 2011 22:49:40 +0000 (UTC), Bent C Dalager
<(E-Mail Removed)> wrote:

[snip]

>$ javac TestCase.java
>$ java TestCase
>$ ls test*
>test-file.tmp test?file.tmp
>$ java TestCase
>Could not create test-file.tmp
>Could not create test?file.tmp
>
>(not sure what I have misconfigured that *******sed up the Unicode on
>that last line)


Maybe nothing. The filename might have been created as you
expected but not display properly.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      06-27-2011
On Sat, 25 Jun 2011 22:58:02 +0100, Tom Anderson
<(E-Mail Removed)> wrote:

>On Fri, 24 Jun 2011, Esmond Pitt wrote:
>
>> On 24/06/2011 8:20 AM, Tom Anderson wrote:
>>> Oh, that's just a modern typesetting fad. It's not intrinsically uppercase.

>>
>> This statement doesn't really mean anything. *All* uppercase is a
>> 'typesetting fad'; nothing is intrinsically uppercase. Or lowercase.

>
>YOU KNOW YOURE QUITE RIGHT THIS MAKES MY LIFE SUBSTANTIALLY EASIER THANKS
>ONCE AGAIN MR PITT


EVENBEFORETHENTHEREWERENOSPACESBETWEENWORDS

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      07-22-2011
On 6/21/2011 8:54 PM, Peter Duniho wrote:
> On 6/21/11 4:37 PM, Gene Wirchenko wrote:
>> On Tue, 21 Jun 2011 15:11:41 -0700, Peter Duniho
>> <(E-Mail Removed)> wrote:
>>
>> [snip]
>>
>>> Speaking of "shoddy", some might consider it "shoddy" to call the
>>> _operating system_ "case-insensitive" when in fact it's the _file
>>> system_ that is case-insensitive.

>>
>> Please do not nitpick.

>
> I have been known to nitpick, but making a distinction between operating
> system and file system is far from that.


That is true.

But it is not correct in the sense of being complete that it is the
file system that is case insensitive.

It is the file system and the command interpreter (shell in
*nix terminology).

Not all command are actual executables.

Arne
 
Reply With Quote
 
Esmond Pitt
Guest
Posts: n/a
 
      07-22-2011
On 22/07/2011 11:14 AM, Peter Duniho wrote:
>> It is the file system and the command interpreter (shell in
>> *nix terminology).

>
> Huh? Inasmuch as the file system can be accessed, and case-sensitivity
> observed, without a command interpreter, I don't see why you are
> dragging the command interpreter into it.


I have to agree with that. I can't see what the command interpreter has
to do with this at all. The file system is case-sensitive so everything
that uses it is as well, including the shells. And of course by default
*everything* in a computer is case-sensitive unless specifically
programmed otherwise.
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      07-22-2011
On 7/21/2011 9:14 PM, Peter Duniho wrote:
> On 7/21/11 5:58 PM, Arne Vajhøj wrote:
>> [...]
>>> I have been known to nitpick, but making a distinction between operating
>>> system and file system is far from that.

>>
>> That is true.
>>
>> But it is not correct in the sense of being complete that it is the
>> file system that is case insensitive.
>>
>> It is the file system and the command interpreter (shell in
>> *nix terminology).

>
> Huh? Inasmuch as the file system can be accessed, and case-sensitivity
> observed, without a command interpreter, I don't see why you are
> dragging the command interpreter into it.
>
> There are lots of other things on a computer besides the file system
> that might or might not be case-sensitive, and you may even have trouble
> working with a case-sensitive file system if those things are not. But I
> don't see how that's relevant here, where it's the case-sensitivity of
> the file system that is at issue.


The topic is the original posters expectation of case insensitivity
of commands because of the OS (Windows) being case insensitive.

That has a lot to with the command interpreter.

Arne


 
Reply With Quote
 
Arne Vajhj
Guest
Posts: n/a
 
      07-22-2011
On 6/22/2011 6:54 AM, Nigel Wade wrote:
> On 21/06/11 22:49, Tom Anderson wrote:
>> On Tue, 21 Jun 2011, Esmond Pitt wrote:
>>
>>> On 21/06/2011 8:09 AM, Martin Gregorie wrote:
>>>
>>>> The Java language system does case-sensitive comparisons between class
>>>> names and the files that contain them when checking that a class name
>>>> matches the file name that contains it
>>>
>>> Nitpicking, but it doesn't really do that, does it. It opens a .class
>>> file of the name the user specified, loads the class(es) it contains,
>>> and tries to find the classname it was looking for among those
>>> classes. It doesn't explicitly compare the filename and the classname.
>>> The operating system gave it HelloWorld.class in response to
>>> 'helloworld.class' because that's how the OS file system happened to
>>> work.

>
>>
>> The way Java does this at the moment means that 'java helloworld', where
>> there is no class 'helloworld', does different things on Windows
>> depending on whether there is a class HelloWorld, hElLoWoRlD,
>> HelloworlD, etc.

>
>
> Does it? What different thing does it do?
>
> As far as a case-insensitive OS/filesystem is concerned, they would all
> appear as the same file. If Java asked for any of those names from the
> filesystem it would get the one file which did exist for any of the
> class names. It would then look in that file for the class it required.
> If the class did not exist in that file it would throw the
> ClassNotFoundException. It cannot do anything else because the
> OS/filesystem simply will not allow it.


The argument is a class name not a file name.

And even on Windows you can have helloworld, HelloWorld and hELLOwORLD.

Classpath is not restricted to current directory.

You can have each of the above class files in different directories
or jar files.

>> That seems pretty shoddy to me. If you're a case-sensitive program
>> running on a case-insensitive operating system, i think it falls on you
>> to pay special attention to case in your dealings with that system: when
>> java opens a class file, it ought to check that the name of the file
>> it's opened actually has the right case, and if it doesn't, discard it,
>> and act as if it had got a file not found error from the operating system.

>
> But Java cannot do this. On a case-insensitve OS/filesystem it simply
> may not be possible for a file to exist called HelloWorld.class.


It does not need to.

OpenVMS with an ODS-2 disk system has all uppercase file names.

You write:
java "HelloWorld"
and Java find HELLOWORLD.CLASS !

> Java is not doing anything wrong. The user is, in assuming that because
> the OS/filesystem is case-insensitive that Java is also. The java
> command syntax is "java<ClassName>" not "java<filename>".


Yes.

> That class
> name is case sensitive, no matter how brain dead the OS or filesystem.
> If you ask Java to run the class helloworld when your class is actually
> HelloWorld, you have asked it to do the wrong thing. Java is perfectly
> correct in telling you this.
>
> If you ask Java to run the class HelloWorld, it does so even on a
> case-insensitive system such as that of the OP. Even if the file is
> called helloworld.class Java still manages to do the right thing.


Yes.

Arne



 
Reply With Quote
 
Arne Vajhj
Guest
Posts: n/a
 
      07-22-2011
On 6/22/2011 2:46 PM, Gene Wirchenko wrote:
> While I am at it, I find the Java error for not finding a program
> to be rather verbose for little use.


It very specifically tell what the problem is.

The exception is very useful.

The gotcha is that understanding the exception requires some
knowledge about Java classes, classpath, classloaders, interaction
with file system etc..

It is not beginner friendly.

In two years you will consider the exception text very logical.

Arne
 
Reply With Quote
 
Arne Vajhj
Guest
Posts: n/a
 
      07-22-2011
On 6/22/2011 2:46 PM, Gene Wirchenko wrote:
> On Wed, 22 Jun 2011 11:06:38 -0700, Patricia Shanahan<(E-Mail Removed)>
> wrote:
>
>> On 6/22/2011 10:16 AM, Gene Wirchenko wrote:
>> ...
>>> Being perfectly correct is not good enough when playing with
>>> others who may well have other priorities. When a program and a user
>>> conflict over interface issues, I think that the user should be the
>>> one to prevail.

>>
>> When dealing with a single-user program that makes sense.
>>
>> Of course, javac and java are both used by many users. How do you
>> propose to let "the user" be the one to prevail, when there are
>> thousands of users with different backgrounds and interface expectations?

>
> Easy on this point. Accepting case-insensitive filenames as
> matching when there is no ambiguity is more helpful to more users than
> throwing an error is.


Actually it did in your case. The java command on Windows
do lookup files case insensitive.

But you get an error if the Java byte code in the file does
not contain the class name you specified.

And Java class name are case sensitive on all platforms.

Arne

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: CLI Java Glitch Jeff Higgins Java 8 07-22-2011 09:50 PM
Re: CLI Java Glitch Tom Anderson Java 2 07-22-2011 09:47 PM
Re: CLI Java Glitch Roedy Green Java 9 07-22-2011 09:45 PM
Re: CLI Java Glitch Jeff Higgins Java 9 06-21-2011 09:45 PM
Re: CLI Java Glitch Stefan Ram Java 2 06-21-2011 07:43 AM



Advertisments