XmlSerializer throws java.lang.reflect.InvocationTargetException
Hi there,
I'm trying to serialize a settings class with xml serializer and get the following error: java.lang.reflect.InvocationTargetException
Here is my settings implementation:
@State( name = "Typo3StormSettings", // must be equal to the class name I think storages = { // @Storage(id = "default", file = StoragePathMacros.PROJECT_FILE), // @Storage(id = "default", file = "/tmp/test/"), // @Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR + "/typo3storm.xml", scheme = StorageScheme.DIRECTORY_BASED) @Storage(id = "dir", file = "/tmp/test/typo3storm.xml", scheme = StorageScheme.DIRECTORY_BASED) } ) public class Typo3StormSettings implements PersistentStateComponent<Typo3StormSettings> { // Those fields should be serialized public boolean enabled = true; public String pathToTypo3; @Transient // Do not serialize this field! protected Project project; public static Typo3StormSettings getInstance(Project project) { Typo3StormSettings settings = ServiceManager.getService(project, Typo3StormSettings.class); if(settings == null){ IdeHelper.logError("Cannot find Typo3Storm Settings"); } settings.project = project; return settings; } @Override public Typo3StormSettings getState() { return this; } @Override public void loadState(Typo3StormSettings typo3StormSettings) { try{ XmlSerializerUtil.copyBean(typo3StormSettings, this); } catch(Exception e){ // IdeHelper.logError(e.getMessage()); // IdeHelper.showDialog(null,"Cannot read the saved settings for Magicento. Please try saving them again from File > Settings > Magicento", "Error in Magicento Settings"); } // autoSetPathToMage(); } public boolean isEnabled() { return enabled; } public String getPathToTypo3() { return getPathToTypo3(); } public void setPathToTypo3(String pathToTypo3) { this.pathToTypo3 = pathToTypo3; } }
And here is a simple testcase, I set up to reproduce the error:
public class Typo3StormSettingsTests { @Test public void settingsCanBeSerialized() { Typo3StormSettings settings = new Typo3StormSettings(); settings.setPathToTypo3("/tmp"); XmlSerializer.serialize(settings); } }
I'm getting the same error, if I run the plugin from within PHPStorm Application, if I uncomment the annotations and use the following @State annotation:
*/ @State( name = "Typo3StormSettings", // must be equal to the class name I think storages = { @Storage(id = "default", file = StoragePathMacros.PROJECT_FILE), @Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR + "/typo3storm.xml", scheme = StorageScheme.DIRECTORY_BASED) } )
It would be really great if you could help me out on that issue!
Best regards,
Mimi
请先登录再写评论。
Hi Michael,
The problem is that your getPathToTypo3() recursively calls itself and stack overflow occurs.
Denis
Hi Denis,
thanks a lot - seems like I was blind...
Greez,
Mimi
Kein problem :)