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 8083363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:26:38+00:00 2026-06-05T17:26:38+00:00

I expected to find XMLStreamReader to be AutoCloseable in Java 7. However, that is

  • 0

I expected to find XMLStreamReader to be AutoCloseable in Java 7. However, that is not the case. Is there a technical reason why StAX reader/writer interfaces were not (or should not be) retrofitted to implement AutoCloseable ? They already have close methods, whose intent is not different from the close method of AutoCloseable.

  • 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-06-05T17:26:42+00:00Added an answer on June 5, 2026 at 5:26 pm

    If you look closer to the close() method of AutoCloseable :

    Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

    Or even Closeable close() method :

    Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

    Whereas the close() method of XMLStreamReader says :

    Frees any resources associated with this Reader. This method does not close the underlying input source.

    Indeed the input source is managed by the Reader which implement the Closeable interface. So it’s the reader that can be close in the try-with-ressource.

    For example :

        XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader reader = null;
        try (FileReader fr = new FileReader("file.xml")) { //Will close the FileReader
            reader = factory.createXMLStreamReader(fr);
            reader.close();
        }
        catch (XMLStreamException ex) {
            if(reader!=null)try {
                reader.close();
            } catch (XMLStreamException ex1) {
                Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting Object Expected error . I am unable to find the reason
Coming from Java, I expected to find some other GUI layout in Visual C++
Is there somewhere I can find out the expected time and space complexities of
I'm trying to find a function that takes a number and outputs the expected
I find that json_encode in php version 5.1.6 will not return empty key for
Why does the following Haskell script not work as expected? find :: Eq a
$rake db:migrate error: could not find expected ':' while scanning a simple key at
Is it expected behavior that two encodings can map to the same decoding? I'm
The following command is working as expected... find /var/lib/mysql -name *.csv -or -name *.txt
The following command is working as expected. What I need to find is the

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.