jimport yields an error every time the class name matches a variable name in the CALLING environments
@sgougeon)
Reported by Samuel GOUGEON (BUG DESCRIPTION:
----------------
jimport yields an error every time the class name matches a variable name in the CALLING environment,
at any level, from the console one to the jimport one if it is run in some function.
This is completely blocking. Indeed, this prevents insuring that a function including
some jimport instructions won't fail just due to symbols defined OUT OF the function.
As a reasonable fact, even protected symbols defined and protected out of a function
do not do that, since local instances mask the outer one.
jimport does not work this way. This bug is just a killer:
--> function test(), jimport java.io.File, disp(File), endfunction
--> clear File, clearglobal File
--> test() // OK
class java.io.File
--> File
Undefined variable: File // So the File class is local. It is not returned to the caller, from the Scilab point of view.
--> File = 1;
--> test()
at line 1 of function test
jimport: An error occurred: A variable with this name is already existing
!!
ERROR LOG:
----------
jimport: An error occurred: A variable with this name is already existing
HOW TO REPRODUCE THE BUG:
-------------------------
function test(), jimport java.io.File, endfunction
clear File, clearglobal File
test()
File
File = 1;
test()
OTHER INFORMATION:
------------------
1) Thread on dev@: https://www.mail-archive.com/dev@lists.scilab.org/msg01241.html
2) The error is yielded in SCI/modules/external_objects/src/cpp/import.cpp , lines #145-155:
-----------------------
if (isNamedVarExist(pvApiCtx, name[i].c_str()))
{
addr = 0;
err = getVarAddressFromName(pvApiCtx, name[i].c_str(), &addr);
if (err.iErr || addr == 0 || !ScilabObjects::isValidExternal(addr, pvApiCtx) || ScilabObjects::getEnvironmentId(addr, pvApiCtx) != envId)
{
freeAllocatedMatrixOfString(rows, cols, className);
delete[] name;
throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("A variable with this name is already existing"));
}
}
-----------------------
Edited by Vincent COUVERT