AccessDeniedException saving files with configurate

Hello, I am having a strange issue working with the Configurate library in Sponge. Sometimes when trying to save a file, I get an AccessDeniedException. This has never happened before, so I am unsure what has gone wrong. The code used to save the file can be found below:

// Ignore undefined variables, this is a snippet.
ConfigurationLoader<?> manager = HoconConfigurationLoader.builder().setFile(file).build();
manager.save(root);

“Checked exception thrown when a file system operation is denied, typically due to a file permission or other access check.”

Likely means that you don’t have permission to write to your config file.

Why could this be? The config file is located in a folder inside of my Documents folder on Windows.

EDIT: The code was running in a separate thread. Moving it to the main thread fixed the problem. Any idea why this happening?

what was file path?

It was config/economylite/currencies.conf.

If you give us the whole exception stack trace, we might be able to track down the problem…

1 Like

Basically what @xfel said. It’d probably also be better to add an EconomyLite#getLogger() function, and then put the manager.save(root) into a try-catch block (as shown in docs :stuck_out_tongue:)

@xfel

That is the entire stack trace. There is nothing else that I could possibly post.

@MichaelFedora

As I said in the main post, that is a snippet of code. In the actual plugin, it is surrounded by a try-catch block.

Oh, sorry.

I really don’t know then; maybe your saving it when it’s already open then? Still have no idea how that could happen, but that’s all I can come up with.

1 Like

I think the issue is that I am saving the same file too many times in too short of a period of time. Since each save is run in an async thread, the file is being saved again before it has finished saving the previous time. Hopefully that all makes sense.

2 Likes

I was gonna say concurrency issues yesterday but had to leave so never pressed post :stuck_out_tongue:

1 Like