简体   繁体   中英

Java 6 - StackOverflowError when trying to copy and paste a file

Java 6
jboss-as-7.1.1.Final

I need to copy and paste a file. Using org.apache.commons.io.FileUtils and I tried with the following code,

If I invoke sync() from a jsp, getting

... java.lang.StackOverflowError at org.apache.catalina.core.ApplicationHttpRequest.removeAttribute(ApplicationHttpRequest.java:280) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.ApplicationHttpRequest.removeAttribute(ApplicationHttpRequest.java:280) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.ApplicationHttpRequest.removeAttribute(ApplicationHttpRequest.java:280) [jbossweb-7.0.13.Final.jar:]

private void sync() {
    try {
        FileUtils.copyFile(new File("C:/jboss-as-7.1.1.Final/standalone/deployments/admin.war/xml/news_src/compose.xml"), 
        new File("C:/jboss-as-7.1.1.Final/standalone/deployments/admin.war/xml/news_dest/compose.xml"));            
    } 
    catch (IOException e) {
        e.printStackTrace();
    }
}

If I run the same code as a standalone java application, the file gets copied and pasted to destination

public static void main(String s[]) {
    try {
        FileUtils.copyFile(new File("C:/jboss-as-7.1.1.Final/standalone/deployments/admin.war/xml/news_src/compose.xml"), 
        new File("C:/jboss-as-7.1.1.Final/standalone/deployments/admin.war/xml/news_dest/compose.xml"));        
    } 
    catch (IOException e) {
        e.printStackTrace();
    }
}

Why am I getting the StackOverflowError when the code invoked in a JBoss environment whereas executing the same code as java application runs successfully? Thanks.

I'm guessing that since you're copying your file into the WAR that has the program that is copying it, it then syncs. Which then copies the file into the WAR which is copying it, and then syncs. Which then copies the file into the WAR which is copying it, and then syncs....

JBoss is smart enough to try to reload code that's changed in the WAR file by redeploying automatically. When you're running as a standalone Java application, there isn't a container, so it doesn't redeploy.

I found a fix for this problem. The action class configuration in my framework, which is an in house built framework, was not correct, thus resulting in action class being called in a loop. I updated that setting, thus preventing action class execution in a loop.

This SO post also guided me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM