[classlib] incorrect error processing in file reading (Windows) caused failure on org.apache.harmony.nio.tests.java.nio.channels.FileLockInterruptionExceptionTest
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HARMONY-4017
URL: https://issues.apache.org/jira/browse/HARMONY-4017
Project: Harmony
Issue Type: Bug
Components: Classlib
Environment: Windows.
Reporter: Sergey Kuksenko
"hyfile_read" function incorrectly process errors.
See part of code:
if (!ReadFile ((HANDLE) fd, buf, nbytes, &bytesRead, NULL))
{
I_32 error = GetLastError ();
portLibrary->error_set_last_error (portLibrary, error, findError (error));
return -1;
}
if (bytesRead == 0)
{
return -1;
}
---------------
Here if "ReadFile" returns a failure then "hyfile_read" set the last error and return -1.
In case of correct operation with reading zero bytes (we are at the End Of File) "hyfile_read"
returns also -1.
This both situations can't be distingueshed from "hyfile_read" caller.
"OSFileSystem.readImpl" do the following
------------------
result =
(jlong) hyfile_read ((IDATA) fd, (void *) (bytes + offset),
(IDATA) nbytes);
if(result == -1 && hyerror_last_error_number() == HYPORT_ERROR_FILE_LOCKED){
throwNewExceptionByName(env, "java/io/IOException", netLookupErrorString(env, HYPORT_ERROR_FILE_LOCKED));
--------------
So URLClassLoader tries to load "FileLockInterruptionExceptionTest.class", read 942 bytes,
try to read next bytes (when reading from InputStream we need to get "-1" as mark of EOF).
And here is all ok.
But in the test suit before this test another test was executed.
The previous test was really tested File Lock Error. And port library last error contains
prev error number.
And exception was thrown. Otherwords we've got the follwoing sequence of IO operations:
1. FileLockedError.
2. Correct reading from file.
3. Read from file, got "-1" as EOF, look into last error state, found obsolete FileLockedError,
throws exception.
thus in case of success IO operation hyfile needs to clean last error state.
Attached file fix the situation with "FileLockInterruptionExceptionTest"
But probably error results from hyfile_read should be refactored or etc. and needs more evaluation.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
|