Object IllegalStateException Problem

P

ptreves

Hello,

I am working on a Java application, and run into the following
exception when trying to save my Network Configuration Parameters. I
have been looking at the execution stack trace for clues to the
problems.

This is the save() method that calls the different objects to save the
individual Configuration<Types>:

public void save() throws XmlException, IOException {
if (logger.isDebugEnabled()) {
logger.debug("Saving systemwide config...");
}

if(!systemwideConfiguration.equals(null)) {
systemwideConfiguration.bufferedSave();
}

if(!rtdbConfiguration.equals(null)) {
rtdbConfiguration.bufferedSave();
}

if(!localeConfiguration.equals(null)) {
localeConfiguration.saveAsCommitted();
}

if(!hmiAccessMgrModel.equals(null)) {
hmiAccessMgrModel.save();
}

if (!CommunicationManager.getInstance().getIsDNA()){
runtimeGUIConfiguration.bufferedSave();
eventLoggerConfiguration.bufferedSave();
dhcpModel.save();
}

if (CommunicationManager.getInstance().getIsDNA()){
if(!timeSyncModel.equals(null)) {
timeSyncModel.save();
}
}

if (logger.isDebugEnabled()) {
logger.debug("Saving systemwide config...completed");
}

setModified(false);
}

Here is the corresponding stack trace:

java.lang.IllegalStateException: Please load a version of an object
before saving!
java.lang.IllegalStateException: Please load a version of an object
before saving!
at
com.gepower.d400.model.config.ConfigurationImpl.getSaveFile(ConfigurationImpl.java:
309)
at
com.gepower.d400.model.config.ConfigurationImpl.bufferedSave(ConfigurationImpl.java:
357)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.gepower.d400.model.config.ConfigurationManager
$SaveProxy.invoke(ConfigurationManager.java:400)
at $Proxy0.bufferedSave(Unknown Source)
at
com.gepower.d400.view.config.systemwide.SystemwideModel.save(SystemwideModel.java:
366)
at com.gepower.d400.view.config.systemwide.SystemwideController
$SaveAction.doLongOperation(SystemwideController.java:272)
at com.gepower.d400.swing.BusyThread.run(BusyThread.java:103)

Now, I am thincking that the command:

hmiAccessMgrModel.equals(null)

is causing the problem and should be re-written as:

hmiAccessMgrModel == null

Suggestions as to what the problem might be ?

Paolo
 
A

Andreas Leitgeb

ptreves said:
java.lang.IllegalStateException: Please load a version of an object
before saving!
at
com.gepower.d400.model.config.ConfigurationImpl.getSaveFile(ConfigurationImpl.java:
309)

Have a closer look at ConfigurationImpl.getSaveFile!

If you quote the method, don't forget to insert a comment indicating
which of the lines is number 309 within ConfigurationImpl.java.
Now, I am thincking that the command:
hmiAccessMgrModel.equals(null)
is causing the problem and should be re-written as:
hmiAccessMgrModel == null

Yes, it really should be re-written as you say.

As it is: if the left side ever *was* null, then you
get a NullPointerException rather than a true result
from xyz.equals(null)
 
P

ptreves

This is the getSaveFile() method:

private FileInfo getSaveFile() throws IOException {
if (object == null) {
throw new IllegalStateException("Please load a version of
an object before saving!");
}

// get the uncommitted version if it is there
FileInfo saveFile =
getConfigurationVersions().get(ConfigurationVersion.UNCOMMITTED);

if (saveFile == null) {
// otherwise create a new temp file
saveFile =
FileInfo.createTempFile(getConfigurationFileName(),
getConfigurationDirectory());
}

return saveFile;
}

Paolo
 
L

Lew

ptreves said:
This is the getSaveFile() method:

private FileInfo getSaveFile() throws IOException {
if (object == null) {
throw new IllegalStateException("Please load a version of
an object before saving!");
}

// get the uncommitted version if it is there
FileInfo saveFile =
getConfigurationVersions().get(ConfigurationVersion.UNCOMMITTED);

if (saveFile == null) {
// otherwise create a new temp file
saveFile =
FileInfo.createTempFile(getConfigurationFileName(),
getConfigurationDirectory());
}

return saveFile;
}

You completely ignored Andreas's advice!

Here's what you need to provide us:
http://sscce.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top