Why am I getting java.lang.StackOverflowError in my code?

In my java class, I have a method staticcalled getProperties()that returns java.util.Properties.

In another method, staticI call this method as:

Properties p = getProperties();

And the method getProperties():

    private static Properties getProperties(){
        Properties properties = new Properties();
        try{         
            InputStream fis = null;                
            fis = new FileInputStream("src/main/resources/fileName.properties"); //In DEBUG mode control comes until here and returns to Properties p = getProperties(); in the calling method every time continuously 
            properties.load(fis);
            fis.close();            
        }catch(Exception e){
            //......
        }
        return properties;
    }

ERROR:

Exception in thread "main" java.lang.StackOverflowError
    at sun.misc.VM.isBooted(VM.java:165)
    at java.util.Hashtable.initHashSeedAsNeeded(Hashtable.java:226)
    at java.util.Hashtable.<init>(Hashtable.java:263)
    at java.util.Hashtable.<init>(Hashtable.java:283)
    at java.util.Properties.<init>(Properties.java:143)
    at java.util.Properties.<init>(Properties.java:135)

In debug mode getProperties (); the method is called continuously without receiving a return statement.

+4
source share
2 answers

I missed the code, which was ok, but I think the error Exception in thread "main" java.lang.StackOverflowError. Maybe something is causing the problem.

Properties p = new Properties();
FileInputStream fs = new FileInputStream("src/main/resources/fileName.properties"));
p.load(fs);
0
source

StackOverflowError , , , , getProperties ?

-1

Source: https://habr.com/ru/post/1619239/


All Articles