Issue with Paths.get failing to convert a path and a string

Does anybody understand why Paths.get is converting NWSConfiguration and “/GASGeneral” to null/GASGeneral???

NWSConfiguration is working just fine, the syntax seems correct, no error codes in Eclipse

This is the error code in the console:

[00:09:23] [Server thread/INFO] [nwsglobaladministrativesystem]: NWS-GAS: C:\Users\User\Desktop\Workbench\Server Hosting\MinecraftForge.\config\nwsglobaladministrativesystem
[00:09:23] [Server thread/INFO] [nwsglobaladministrativesystem]: NWS-GAS: null\GASGeneral.conf
[00:09:23] [Server thread/INFO] [nwsglobaladministrativesystem]: NWS-GAS: Checking the existence of the General configuration file.
[00:09:23] [Server thread/WARN] [nwsglobaladministrativesystem]: NWS-GAS: The Configuration file was not found! Attempting to create it…
[00:09:23] [Server thread/ERROR] [nwsglobaladministrativesystem]: NWS-GAS: Configuration file was unsuccessful!
[00:09:23] [Server thread/INFO] [STDERR]: [net.newworldservers.globaladministrativesystem.globaladministrativesystem:createCheckConfigFile:86]: java.nio.file.NoSuchFileException: null\GASGeneral.conf

I had both variables log their values to show it’s Paths.get failing to actually convert NWSConfiguration to an actual path.

Here is the code:

@Inject
@ConfigDir(sharedRoot = false)
private Path NWSConfiguration;

//Configuration Creation Setup

private Path generalConfigFile = Paths.get(NWSConfiguration + "/GASGeneral.conf");
private ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setPath(generalConfigFile).build();
private CommentedConfigurationNode configNode;

//Variables

private String pluginTag = "NWS-GAS: ";

//Methods

public Logger getLogger() {
	
	return logger;
}

private boolean createCheckConfigFile(String configFileName, Path directory, Path configFile) {
	
	getLogger().info(pluginTag + NWSConfiguration);
	getLogger().info(pluginTag + generalConfigFile);
	getLogger().info(pluginTag + "Checking the existence of the " + configFileName + " configuration file.");
	
	if(!Files.exists(directory)) {
		try {
			
				getLogger().warn(pluginTag + directory + " not found! Attempting to create the directory...");
				Files.createDirectories(directory);
				getLogger().info(pluginTag + "Directory creation was successful!");
		}catch(IOException io){
			
				getLogger().error(pluginTag + "Directory creation was unsuccessful!");
				io.printStackTrace();	
				return false;
		}
	}
	
	if(!Files.exists(configFile)) {
		try {
			
				getLogger().warn(pluginTag + "The Configuration file was not found! Attempting to create it...");
				Files.createFile(configFile);
				getLogger().info(pluginTag + "Configuration file creation was successful!");
		}catch(IOException io) {	
			
				getLogger().error(pluginTag + "Configuration file was unsuccessful!");
				io.printStackTrace();
				return false;
		}
	
	}
	
	getLogger().info(pluginTag + "Configuration file found.");
	return true;
}

@Listener
public void onPreInit(GamePreInitializationEvent event){
	
	if(!createCheckConfigFile("General", NWSConfiguration, generalConfigFile)) {
		getLogger().error(pluginTag + "Unable to create or find a usable configuration file! System shutting down to prevent crashing...");
	}
}

This has been giving me a headache for about 3 hours, I would appreciate any help. Thank you.

Guice Injection is a powerful tool, but you need to have an understanding of how it works and know the rules to use it properly. Injections don’t happen until after the constructor finishes initializing, and at that point you’ve already created your default variables. So, at the time of initialization, here’s what you actually have.

@Inject
@ConfigDir(sharedRoot = false)
private Path NWSConfiguration = null;

private Path generalConfigFile = Paths.get(null + "/GASGeneral.conf");

You can see this printout here:

[00:09:23] [Server thread/INFO] [nwsglobaladministrativesystem]: NWS-GAS: null\GASGeneral.conf

So, what can you do about it? The way I personally recommend is to have a separate file that handles your configuration; keep the @Plugin class as your controller that handles the initialization and state listeners and you’ll be better off in the long run.

Next, you should use Path#resolve instead of combining Strings - there are a couple of reasons, but that is the indended way to get a subfile/folder from a path.

Additionally, it’s not often that you should be creating a configuration file directly. I strongly recommend making use of the AssetAPI, which will help streamline the creation of your config.

As a final note, I have no idea what you mean by System shutting down to prevent crashing.... I would be very careful with attempting to shut down the server (actually, just don’t do it).

Heh, should’ve figured initialization order, had that issue when dev’ing for RUST. Plus this is what I get for skipping around the documentation, I didn’t read the Asset part yet, I was just going with Configuration and it mentioned nothing about creating one.

The shutdown part isn’t shutting down the server, just disabling the plugin so it doesn’t keep running and hit a fatal error because the config wasn’t there. Anyways, thanks for the help, looks like I got more research to do.