xt
8 楼
class Util {
public boolean compareFile( File f1, File f2 )
{ // Read and compare content of file }
} // end class Util
class Test
{
...
if( !Util.compareFile( f1, f2 ) ) {
System.out.println( "Different" );
}
boolean same = Util.compareFile( f1, f2 );
if( same ) {
System.out.println( "Same" );
}
...
}
Use f1 and f2 pointing 2 identical files
Result:
Different
Same
public boolean compareFile( File f1, File f2 )
{ // Read and compare content of file }
} // end class Util
class Test
{
...
if( !Util.compareFile( f1, f2 ) ) {
System.out.println( "Different" );
}
boolean same = Util.compareFile( f1, f2 );
if( same ) {
System.out.println( "Same" );
}
...
}
Use f1 and f2 pointing 2 identical files
Result:
Different
Same
c*t
9 楼
Your posted code is impossible since compareFile is not a static
function.
【在 xt 的大作中提到】
: class Util {
: public boolean compareFile( File f1, File f2 )
: { // Read and compare content of file }
: } // end class Util
: class Test
: {
: ...
: if( !Util.compareFile( f1, f2 ) ) {
: System.out.println( "Different" );
: }
function.
【在 xt 的大作中提到】
: class Util {
: public boolean compareFile( File f1, File f2 )
: { // Read and compare content of file }
: } // end class Util
: class Test
: {
: ...
: if( !Util.compareFile( f1, f2 ) ) {
: System.out.println( "Different" );
: }
m*t
13 楼
Oh yeah, IBM is not only rubbish but also mind controlling, because evidently
everybody else who uses jikes and dares to write statements as complicated as
"if (!foo())" all got screwed up big time by this rubbish JVM, and yet they
just stayed silent all the time.
8-)
【在 xt 的大作中提到】
:
: Technically I can't. I ran the debugger into it
: and found the function returns true but that if( !...)
: got in. So I extracted the return value to a variable
: everything becomes normal.
: IBM is rubbish
xt
14 楼
evidently
as
IBM JVM is rubbish, no matter how they boast that they have the best compilers
in the world - which I very much doubt. Compared with IBM, Miscrosoft is much
better and should never be charged under antitrust law.
【在 m******t 的大作中提到】
:
: Oh yeah, IBM is not only rubbish but also mind controlling, because evidently
: everybody else who uses jikes and dares to write statements as complicated as
: "if (!foo())" all got screwed up big time by this rubbish JVM, and yet they
: just stayed silent all the time.
: 8-)
xt
15 楼
evidently
as
FYI, this is actually a known bug! I don't know if Sun JDK handles it right,
but IBM JDK, which came with my WebSphere, does not handle it right:
Class Util{
public static boolean check( File canonFile, String dirName)
throws SecurityException, IOException
{
File dir = new File( dirName );
if( !dir.isDirectory() ) throw new FileNotFoundException( dirName+ " is not
a directory");
// Find the most recent file in the directory
File[] files = dir.listFiles();
if( files==null || files.l
【在 m******t 的大作中提到】
:
: Oh yeah, IBM is not only rubbish but also mind controlling, because evidently
: everybody else who uses jikes and dares to write statements as complicated as
: "if (!foo())" all got screwed up big time by this rubbish JVM, and yet they
: just stayed silent all the time.
: 8-)
m*t
16 楼
I think I missed your point in the OP. What exactly is the known bug? Are
you saying jikes has side effects in their file reading methods?
【在 xt 的大作中提到】
:
: evidently
: as
: FYI, this is actually a known bug! I don't know if Sun JDK handles it right,
: but IBM JDK, which came with my WebSphere, does not handle it right:
: Class Util{
: public static boolean check( File canonFile, String dirName)
: throws SecurityException, IOException
: {
: File dir = new File( dirName );
xt
17 楼
right,
Nothing went wrong with file reading. I tracked with debugger. The bytes
from both files come out identical. In the method, the "return true;" was
reached. It is the complex boolean expression being evaluated wrong in
the if( !... ) line. Frankly after 2 years using the quality products
from IBM, I am still not enjoying any of them.
【在 m******t 的大作中提到】
:
: I think I missed your point in the OP. What exactly is the known bug? Are
: you saying jikes has side effects in their file reading methods?
m*t
18 楼
Well then I didn't miss your point. So can you reduce this to something like:
boolean foo() { return true; }
if (!foo()) System.out.println("false");
boolean fooRes = foo();
if (fooRes) System.out.println("true");
【在 xt 的大作中提到】
:
: right,
: Nothing went wrong with file reading. I tracked with debugger. The bytes
: from both files come out identical. In the method, the "return true;" was
: reached. It is the complex boolean expression being evaluated wrong in
: the if( !... ) line. Frankly after 2 years using the quality products
: from IBM, I am still not enjoying any of them.
xt
19 楼
like:
Nah, I don't think IBM is that silly. Actually it works fine on these.
For example, I have never had to use a boolean to store a Vector.isEmpty().
I just don't know why it failed in my case. Maybe it is just too complicated
for that compiler/interpreter to understand. I am also pretty sure
I did not turn on any optimisation, since I am using -g option.
【在 m******t 的大作中提到】
:
: Well then I didn't miss your point. So can you reduce this to something like:
: boolean foo() { return true; }
: if (!foo()) System.out.println("false");
: boolean fooRes = foo();
: if (fooRes) System.out.println("true");
st
20 楼
your "code" no sense, it has numerous errors...
【在 xt 的大作中提到】
:
: like:
: Nah, I don't think IBM is that silly. Actually it works fine on these.
: For example, I have never had to use a boolean to store a Vector.isEmpty().
: I just don't know why it failed in my case. Maybe it is just too complicated
: for that compiler/interpreter to understand. I am also pretty sure
: I did not turn on any optimisation, since I am using -g option.
【在 xt 的大作中提到】
:
: like:
: Nah, I don't think IBM is that silly. Actually it works fine on these.
: For example, I have never had to use a boolean to store a Vector.isEmpty().
: I just don't know why it failed in my case. Maybe it is just too complicated
: for that compiler/interpreter to understand. I am also pretty sure
: I did not turn on any optimisation, since I am using -g option.
m*t
21 楼
I thought you said it was a known bug? How can the complexity of the method
you are calling affect the evaluation of the if statement *after* the method
returns?
I'm still suspecting there is some side effects in your check() method. Did
you try swapping the two calls?
【在 xt 的大作中提到】
:
: like:
: Nah, I don't think IBM is that silly. Actually it works fine on these.
: For example, I have never had to use a boolean to store a Vector.isEmpty().
: I just don't know why it failed in my case. Maybe it is just too complicated
: for that compiler/interpreter to understand. I am also pretty sure
: I did not turn on any optimisation, since I am using -g option.
v*e
22 楼
I don't like IBM, but I can't agree with you on this one. Looks like your
check() method is not idempotent. Check this :
boolean check1 = check(arg1, arg2);
boolean check2 = check(arg1, arg2);
System.out.println("check1:" + check1 + " check2:" + check2);
they
not
【在 xt 的大作中提到】
:
: like:
: Nah, I don't think IBM is that silly. Actually it works fine on these.
: For example, I have never had to use a boolean to store a Vector.isEmpty().
: I just don't know why it failed in my case. Maybe it is just too complicated
: for that compiler/interpreter to understand. I am also pretty sure
: I did not turn on any optimisation, since I am using -g option.
check() method is not idempotent. Check this :
boolean check1 = check(arg1, arg2);
boolean check2 = check(arg1, arg2);
System.out.println("check1:" + check1 + " check2:" + check2);
they
not
【在 xt 的大作中提到】
:
: like:
: Nah, I don't think IBM is that silly. Actually it works fine on these.
: For example, I have never had to use a boolean to store a Vector.isEmpty().
: I just don't know why it failed in my case. Maybe it is just too complicated
: for that compiler/interpreter to understand. I am also pretty sure
: I did not turn on any optimisation, since I am using -g option.
c*t
23 楼
Jesus, the code doesn't even compile with so many syntax errors.
It also contains semantic errors (second parameter of check is
String, not File).
I guess that you'd better post some real code.
99.99999999% of the time, some bugs you claim that is compiler/JVM
bug, it is in fact of your own fault.
【在 xt 的大作中提到】
:
: like:
: Nah, I don't think IBM is that silly. Actually it works fine on these.
: For example, I have never had to use a boolean to store a Vector.isEmpty().
: I just don't know why it failed in my case. Maybe it is just too complicated
: for that compiler/interpreter to understand. I am also pretty sure
: I did not turn on any optimisation, since I am using -g option.
It also contains semantic errors (second parameter of check is
String, not File).
I guess that you'd better post some real code.
99.99999999% of the time, some bugs you claim that is compiler/JVM
bug, it is in fact of your own fault.
【在 xt 的大作中提到】
:
: like:
: Nah, I don't think IBM is that silly. Actually it works fine on these.
: For example, I have never had to use a boolean to store a Vector.isEmpty().
: I just don't know why it failed in my case. Maybe it is just too complicated
: for that compiler/interpreter to understand. I am also pretty sure
: I did not turn on any optimisation, since I am using -g option.
xt
24 楼
It is not the orginal source code. Why? The orginal source
code is about 1000 lines long with 2 classes! Also yu
won't be able to compile it anyway. It depends on a large
number of files in classpath.
This time, I am pretty sure it is the JVM that went wrong.
Otherwise how can you explain the fact that after I store
the return value with a variable, it becomes normal?
【在 c*****t 的大作中提到】
: Jesus, the code doesn't even compile with so many syntax errors.
: It also contains semantic errors (second parameter of check is
: String, not File).
: I guess that you'd better post some real code.
: 99.99999999% of the time, some bugs you claim that is compiler/JVM
: bug, it is in fact of your own fault.
xt
25 楼
I do not know. This is exactly what I have observed with debugger,
after numerous times of failurs for no good reason.
Again, it is IBM. I am not surprised of anything insensible
from them any more. Do you know if you add int with long on
IBM JVM, you are not guaranteed a correct result? Don't tell
me this has been fixed with C more than 20 years ago.
How? I am just giving an example. In my code I have only one line
to call it.
【在 m******t 的大作中提到】
:
: I thought you said it was a known bug? How can the complexity of the method
: you are calling affect the evaluation of the if statement *after* the method
: returns?
: I'm still suspecting there is some side effects in your check() method. Did
: you try swapping the two calls?
c*t
26 楼
sigh, did you every get rid of the ! and run the program again?
Your check() maybe suspicious s.t running it again would return
a different result. Also, you may have to close the file.
【在 xt 的大作中提到】
:
: I do not know. This is exactly what I have observed with debugger,
: after numerous times of failurs for no good reason.
: Again, it is IBM. I am not surprised of anything insensible
: from them any more. Do you know if you add int with long on
: IBM JVM, you are not guaranteed a correct result? Don't tell
: me this has been fixed with C more than 20 years ago.
: How? I am just giving an example. In my code I have only one line
: to call it.
Your check() maybe suspicious s.t running it again would return
a different result. Also, you may have to close the file.
【在 xt 的大作中提到】
:
: I do not know. This is exactly what I have observed with debugger,
: after numerous times of failurs for no good reason.
: Again, it is IBM. I am not surprised of anything insensible
: from them any more. Do you know if you add int with long on
: IBM JVM, you are not guaranteed a correct result? Don't tell
: me this has been fixed with C more than 20 years ago.
: How? I am just giving an example. In my code I have only one line
: to call it.
xt
27 楼
OH, I forgot to close the file. haha
Anyway, it is only a test program. I have to write about 5000 lines in 2
weeks. So what can you expect?
I am normally a very defensive programmer. Even my student say I am the
most picky programmer he ever met.
【在 c*****t 的大作中提到】
: sigh, did you every get rid of the ! and run the program again?
: Your check() maybe suspicious s.t running it again would return
: a different result. Also, you may have to close the file.
xt
28 楼
On 2nd though, I didn't. Here's the method "readFile":
public static byte[] readFile( String fileName ) throws
FileNotFoundException, IOException
{
byte[] buff=null;
// Read in the file content
InputStream in=null;
try{
in = new FileInputStream( fileName );
buff = new byte[in.available()];
in.read( buff );
} finally {
if( in!=null ) {
try{
in.close();
} catch ( Exception e ) {
// Ignore
}
}
}
return buff;
}
【在 c*****t 的大作中提到】
: sigh, did you every get rid of the ! and run the program again?
: Your check() maybe suspicious s.t running it again would return
: a different result. Also, you may have to close the file.
c*t
29 楼
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This line could be a problem. in.available() may not necessarily
equal to the file size. You should use File.length() to obtain
the actual file size.
【在 xt 的大作中提到】
:
: On 2nd though, I didn't. Here's the method "readFile":
: public static byte[] readFile( String fileName ) throws
: FileNotFoundException, IOException
: {
: byte[] buff=null;
: // Read in the file content
: InputStream in=null;
: try{
: in = new FileInputStream( fileName );
c*t
31 楼
The thing is that when your code not working, you blame IBM for the
problem, while on the other hand, you used codes don't have the documented
features. Those things just complicate the debugging process.
【在 xt 的大作中提到】
:
: Right. As long as it works temperarily, who cares. It's only for testing
: not a product.
problem, while on the other hand, you used codes don't have the documented
features. Those things just complicate the debugging process.
【在 xt 的大作中提到】
:
: Right. As long as it works temperarily, who cares. It's only for testing
: not a product.
x*n
32 楼
/* Returns
* named by the argument exists and is equal to the string
*
*/
the Boolean.getBoolean(String systemPropertyName) tests agains the system
property, not the string itself.
I especially don't appreciate your insulting a company without first check
if that's your own fault (misunderstanding, or ignorance, or the like).
Also, even if this is it's bug, you still need to test it against other JVMs
b
【在 xt 的大作中提到】
: Boolean.getBoolean("true")=false
true
if and only if the system property* named by the argument exists and is equal to the string
*
"true"
.*/
the Boolean.getBoolean(String systemPropertyName) tests agains the system
property, not the string itself.
I especially don't appreciate your insulting a company without first check
if that's your own fault (misunderstanding, or ignorance, or the like).
Also, even if this is it's bug, you still need to test it against other JVMs
b
【在 xt 的大作中提到】
: Boolean.getBoolean("true")=false
e*g
33 楼
haha.
but that one is indeed a very bad API. everybody was hit by it.
【在 x***n 的大作中提到】
: /* Returns
: * named by the argument exists and is equal to the string
: *
: */
: the Boolean.getBoolean(String systemPropertyName) tests agains the system
: property, not the string itself.
: I especially don't appreciate your insulting a company without first check
: if that's your own fault (misunderstanding, or ignorance, or the like).
: Also, even if this is it's bug, you still need to test it against other JVMs
: b
but that one is indeed a very bad API. everybody was hit by it.
【在 x***n 的大作中提到】
: /* Returns
true
if and only if the system property: * named by the argument exists and is equal to the string
: *
"true"
.: */
: the Boolean.getBoolean(String systemPropertyName) tests agains the system
: property, not the string itself.
: I especially don't appreciate your insulting a company without first check
: if that's your own fault (misunderstanding, or ignorance, or the like).
: Also, even if this is it's bug, you still need to test it against other JVMs
: b
xt
37 楼
相关阅读
Java 1-to-1 chat programRe: Is java using call by reference?apply Java board BFCryptoquivalence ClassesRe: how to handle Null in JDBC servlet?ldap exampleRe: Java能做出象netmeeting一样可传影象的程序吗Re: 求助!!!!关于java的后台程序Re: GridLayout一问Re: 如何在两个窗口之间通信?性能评价要恰当Re: new problem, using browser to run java applet一个Java程序员的话----前前前因[转载] Java版诚招版副Re: jbuilder current working dir?今天写了一个游戏JFTP bug test helpRead this about JAppletBBS CLIENT 不需要中文系统 v0.0.0.0.00001Java basic concept(2)