You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/04/15 11:56:56 UTC

(commons-configuration) 01/05: Internal refactoring

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-configuration.git

commit 673e9a3765eb3f238d354b612b561e04ad90edc5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Apr 15 07:39:53 2026 -0400

    Internal refactoring
---
 .../apache/commons/configuration2/io/FileHandler.java | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/commons/configuration2/io/FileHandler.java b/src/main/java/org/apache/commons/configuration2/io/FileHandler.java
index 45575b147..0feb3d163 100644
--- a/src/main/java/org/apache/commons/configuration2/io/FileHandler.java
+++ b/src/main/java/org/apache/commons/configuration2/io/FileHandler.java
@@ -314,11 +314,13 @@ public class FileHandler {
      * content object is accessed.
      *
      * @throws ConfigurationException if not content object is defined
+     * @return {@code this} instance.
      */
-    private void checkContent() throws ConfigurationException {
+    FileHandler checkContent() throws ConfigurationException {
         if (getContent() == null) {
             throw new ConfigurationException("No content available!");
         }
+        return this;
     }
 
     /**
@@ -329,8 +331,7 @@ public class FileHandler {
      * @throws ConfigurationException if not content object is defined
      */
     private FileLocator checkContentAndGetLocator() throws ConfigurationException {
-        checkContent();
-        return getFileLocator();
+        return checkContent().getFileLocator();
     }
 
     /**
@@ -641,8 +642,7 @@ public class FileHandler {
      * @throws ConfigurationException if an error occurs during the load operation
      */
     public void load(final Reader in) throws ConfigurationException {
-        checkContent();
-        injectNullFileLocator();
+        checkContent().injectNullFileLocator();
         loadFromReader(in);
     }
 
@@ -731,8 +731,7 @@ public class FileHandler {
      * @throws ConfigurationException if an error occurs
      */
     private void loadFromStream(final InputStream in, final String encoding, final URL url) throws ConfigurationException {
-        checkContent();
-        final SynchronizerSupport syncSupport = fetchSynchronizerSupport();
+        final SynchronizerSupport syncSupport = checkContent().fetchSynchronizerSupport();
         syncSupport.lock(LockMode.WRITE);
         try {
             injectFileLocator(url);
@@ -1008,8 +1007,7 @@ public class FileHandler {
      * @throws ConfigurationException if an error occurs during the save operation
      */
     public void save(final Writer out) throws ConfigurationException {
-        checkContent();
-        injectNullFileLocator();
+        checkContent().injectNullFileLocator();
         saveToWriter(out);
     }
 
@@ -1022,8 +1020,7 @@ public class FileHandler {
      * @throws ConfigurationException if an error occurs
      */
     private void saveToStream(final OutputStream out, final String encoding, final URL url) throws ConfigurationException {
-        checkContent();
-        final SynchronizerSupport syncSupport = fetchSynchronizerSupport();
+        final SynchronizerSupport syncSupport = checkContent().fetchSynchronizerSupport();
         syncSupport.lock(LockMode.WRITE);
         try {
             injectFileLocator(url);