Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6243471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:08:45+00:00 2026-05-24T12:08:45+00:00

As the title says, when attempting to do folder.open() it fails, doesn’t throw an

  • 0

As the title says, when attempting to do folder.open() it fails, doesn’t throw an error though so it is proving hard to find a reason. In my debug console the following error does appear but it may/may not be related (This only shows up after pressing resume after the folder.open() breakpoint).

I am using the JavaMail API for Android for development. Everything was working fine for IMAP servers but I need to be able to connect to POP3 mail servers also. The store being connected to is GMAIL and all the neccessary settings have been changed on my GMAIL account.

04-12 13:22:26.682: INFO/dalvikvm(436): Ljava/lang/IllegalStateException;: Folder is not Open
04-12 13:22:26.682: INFO/dalvikvm(436):     at com.sun.mail.pop3.POP3Folder.checkOpen(POP3Folder.java:512)
04-12 13:22:26.682: INFO/dalvikvm(436):     at com.sun.mail.pop3.POP3Folder.close(POP3Folder.java:227)
04-12 13:22:26.682: INFO/dalvikvm(436):     at com.sun.mail.pop3.POP3Folder.finalize(POP3Folder.java:506)
04-12 13:22:26.682: INFO/dalvikvm(436):     at dalvik.system.NativeStart.run(Native Method)

The connection method for pop3 is as follows:

String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

        Properties pop3Props = new Properties();

        pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
        pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
        pop3Props.setProperty("mail.pop3.port",  "995");
        pop3Props.setProperty("mail.pop3.socketFactory.port", "995");

        URLName url = new URLName("pop3", "pop.gmail.com", 995, "",
                "******@googlemail.com", "*****");

        //session = Session.getInstance(pop3Props, null);
        Session session = Session.getInstance(pop3Props, new javax.mail.Authenticator() 
        {   
            protected PasswordAuthentication getPasswordAuthentication() 
            {
                return new PasswordAuthentication("***********", "*****");
            }
        });

        session.setDebug(true);

        store = new POP3SSLStore(session, url);
        store.connect();

The method for connecting to a store is as follow (Where the problems are being encountered):

folders = store.getFolder("INBOX");
        //Folder folder = store.getFolder("INBOX");
        if (folders.isOpen()) 
        {
            if ((folders.getMode() & Folder.READ_WRITE) != 0) 
            {
                folders.close(false);
                folders.open(Folder.READ_ONLY);
            }
        } 
        else 
        {
            try
            {
                folders.open(Folder.READ_ONLY);
            }
            catch (Exception e)
            {
                Log.i("Folder Opening,", e.toString());
            }
        }

Any ideas would be helpful! Session has been debugged and no problems are apparent. If any more information is needed for you to assist do not hesitate to ask! I’m sure I’m not the only person getting this problem.

Thanks!
Rhys

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:08:46+00:00Added an answer on May 24, 2026 at 12:08 pm

    So, we came across this issue as well.

    I took a look at the implementation of POP3Folder where that exception is being triggered.

    It seems that POP3Folder is overriding finalize() in order to perform some cleanup before the object goes out of existence. The finalize() override calls close() which checks if the folder is open, and if it isn’t, the IllegalStateException you see is thrown.

    This is why you may be seeing it sporadically; it happens when the GC comes along to take a look at your object, and at that point, the folder may have been closed already, so by the time finalize() calls close(), the check to see if the folder is open will throw the exception.

    Now, I can’t speak to whether this is smart or dumb. It does seem that the code would be better if close() would just ignore the fact that the folder is already closed and move along, instead of throwing an exception.

    POP3Folder takes a parameterized constructor. Unfortunately, it isn’t public or protected, so you can’t simply derive from it and override the close() method, removing the check for whether the folder is open.

    But, since the exception call stack originates from finalize(), it should make it less of a danger to leave alone, since any exception thrown from finalize() will typically only halt the finalization process (garbage collection) for that object, without causing much more damage.

    Would love to see a proper solution to this, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says, I want to know the exact reason why JavaScript is
The Title says everything.. Searched Google and Stackoverflow and didn't find something similiar..
Title says what i'm trying to do. I can successfully generate an assembly if
Title says it mostly. I want to add a simple extension method to the
Question title says it all really - a lot slower than VS2005, with a
As title says, how do I call a java class method from a jsp,
The title says it mostly. If I have an object in Python and want
The title says it! I know that Jon Skeet was working on an implementation
The title says enough I think. I have a full quality BufferedImage and I
As title says, im having trouble with my junit tests passing for checking if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.