The return code may actually be the one for an access violation, but as the tests are running through npm, the return code may just be 1. Or something else is breaking, but when running the code on my local machine, I get an access violation.
Yes, with quite a few, actually. As I wrote a wrapper around the JNI apis, I had to work with a lot of raw pointers. But, here's the thing: On every other system except windows 32-bit I've never encountered an access violation even once. Better yet, in the commit I've referenced only a Vec containing possibly some strings gets added and this causes the access violation. But when removing these 3 lines, everything works flawlessly. I've also encountered an access violation while adding other things, but this one was the easiest to show that clearly, something is wrong here (duh).
And it gets even better: If I add a println!
in the method where I've added the 3 lines for the Vec, the access violation is magically gone. It's truly wild.
So I don't think a null pointer not being handled by me correctly is the issue, as it just works™ on any other system/configuration.
So in summary, the access violation here is caused by me adding a vector to another one:
loaded_jars.extend(cp.clone());
// or
loaded_jars.append(&mut cp.clone());
But again, there are many other things that caused, another great one would be this:
Something like this caused an access violation somewhere
fn not_ok(dirs: Vec<String>, ignore_unreadable: bool) -> napi::Result<Vec<String>> {
let mut res = Vec::<String>::new();
for dir in dirs {
let glob_res = glob(dir.as_str())
.map_napi_err()?
.into_iter()
.map(|f| f.map_napi_err())
.collect::<napi::Result<Vec<_>>>();
match glob_res {
Ok(f) => {
for file in f {
if file.is_file() {
res.push(file.to_str().unwrap().to_string());
}
}
},
Err(e) => {
if !ignore_unreadable {
Err(e)?;
}
}
};
}
Ok(res)
}
But changing it to this worked fine:
fn this_is_fine(dirs: Vec<String>, ignore_unreadable: bool) -> napi::Result<Vec<String>> {
dirs.into_iter()
.map(|f| glob(f.as_str()).map_napi_err())
.collect::<napi::Result<Vec<_>>>()?
.into_iter()
.flat_map(|f| f)
.map(|f| f.map_napi_err())
.filter_map(|f| match f {
Ok(f) => Some(
f.to_str()
.ok_or("Failed to convert path to string".into_napi_err())
.map(|f| f.to_string()),
),
Err(e) => {
if ignore_unreadable {
None
} else {
Some(Err(e))
}
}
})
.collect()
}
Both methods should do exactly the same: Iterate over a list of glob patterns and find all files matching those patterns. But one causes a kind of untraceable access violation, the other doesn't.
And I'm not even working with raw pointers at this point, that's the only thing I've changed.