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 2022/11/20 14:53:25 UTC

[commons-bcel] branch master updated (1a99a1e5 -> 24630299)

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

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


    from 1a99a1e5 Fix an instance of IAE when it should be ClassFormatException
     new c2bb9264 Javadoc
     new 7603760b Use try-with-resources
     new 08a313c0 Reuse constant instead of magic number
     new 24630299 Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-bcel.git

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/examples/Package.java                         | 10 ++++++----
 src/main/java/org/apache/bcel/util/ClassPath.java | 21 ++++++++++++++-------
 2 files changed, 20 insertions(+), 11 deletions(-)


[commons-bcel] 01/04: Javadoc

Posted by gg...@apache.org.
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-bcel.git

commit c2bb9264e3a930eac3fa0d74e576f330aa3596e4
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Sat Nov 19 19:27:24 2022 -0500

    Javadoc
---
 src/main/java/org/apache/bcel/util/ClassPath.java | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/bcel/util/ClassPath.java b/src/main/java/org/apache/bcel/util/ClassPath.java
index 783a9c85..7f665ccb 100644
--- a/src/main/java/org/apache/bcel/util/ClassPath.java
+++ b/src/main/java/org/apache/bcel/util/ClassPath.java
@@ -670,6 +670,10 @@ public class ClassPath implements Closeable {
     }
 
     /**
+     * Gets an InputStream.
+     * <p>
+     * The caller is responsible for closing the InputStream.
+     * </p>
      * @param name fully qualified class name, e.g. java.lang.String
      * @return input stream for class
      * @throws IOException if an I/O error occurs.
@@ -679,24 +683,27 @@ public class ClassPath implements Closeable {
     }
 
     /**
-     * Return stream for class or resource on CLASSPATH.
+     * Gets an InputStream for a class or resource on the classpath.
+     * <p>
+     * The caller is responsible for closing the InputStream.
+     * </p>
      *
-     * @param name fully qualified file name, e.g. java/lang/String
+     * @param name   fully qualified file name, e.g. java/lang/String
      * @param suffix file name ends with suff, e.g. .java
      * @return input stream for file on class path
      * @throws IOException if an I/O error occurs.
      */
     public InputStream getInputStream(final String name, final String suffix) throws IOException {
-        InputStream inputStream = null;
         try {
             final java.lang.ClassLoader classLoader = getClass().getClassLoader();
-            inputStream = classLoader == null ? null : classLoader.getResourceAsStream(name + suffix); // may return null
+            @SuppressWarnings("resource") // closed by caller
+            InputStream inputStream = classLoader == null ? null : classLoader.getResourceAsStream(name + suffix);
+            if (inputStream != null) {
+                return inputStream;
+            }
         } catch (final Exception ignored) {
             // ignored
         }
-        if (inputStream != null) {
-            return inputStream;
-        }
         return getClassFile(name, suffix).getInputStream();
     }
 


[commons-bcel] 04/04: Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-bcel.git

Posted by gg...@apache.org.
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-bcel.git

commit 24630299e1402294a87be0255cf99024bb9536ce
Merge: 08a313c0 1a99a1e5
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Sun Nov 20 09:53:11 2022 -0500

    Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-bcel.git

 src/changes/changes.xml                                   |   1 +
 src/main/java/org/apache/bcel/classfile/StackMapType.java |   2 +-
 src/test/java/org/apache/bcel/OssFuzzTestCase.java        |   5 +++++
 src/test/resources/ossfuzz/issue53543/Test.class          | Bin 0 -> 57 bytes
 4 files changed, 7 insertions(+), 1 deletion(-)


[commons-bcel] 02/04: Use try-with-resources

Posted by gg...@apache.org.
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-bcel.git

commit 7603760bb9c6717539089f7a7a6eb0fa4a265dc8
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Sat Nov 19 19:27:36 2022 -0500

    Use try-with-resources
---
 src/examples/Package.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/examples/Package.java b/src/examples/Package.java
index efd24acd..5cf61ef3 100644
--- a/src/examples/Package.java
+++ b/src/examples/Package.java
@@ -177,7 +177,9 @@ public class Package {
                 clName = clName.substring(0, clName.length() - 6);
             }
             clName = clName.replace('.', '/');
-            clazz = new ClassParser(classPath.getInputStream(clName), clName).parse();
+            try (final InputStream inputStream = classPath.getInputStream(clName)) {
+                clazz = new ClassParser(inputStream, clName).parse();
+            }
             // here we create the root set of classes to process
             addDependents(clazz);
             System.out.println("Packaging for class: " + clName);
@@ -196,8 +198,8 @@ public class Package {
             final String name = dependents.firstKey();
             final String from = dependents.remove(name);
             if (allClasses.get(name) == null) {
-                try (final InputStream is = classPath.getInputStream(name)) {
-                    clazz = new ClassParser(is, name).parse();
+                try (final InputStream inputStream = classPath.getInputStream(name)) {
+                    clazz = new ClassParser(inputStream, name).parse();
                     addDependents(clazz);
                 } catch (final IOException e) {
                     // System.err.println("Error, class not found " + name );


[commons-bcel] 03/04: Reuse constant instead of magic number

Posted by gg...@apache.org.
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-bcel.git

commit 08a313c0b79865297952b6714eaaf9a316983b73
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Sat Nov 19 19:28:29 2022 -0500

    Reuse constant instead of magic number
---
 src/examples/Package.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/examples/Package.java b/src/examples/Package.java
index 5cf61ef3..5c6bafab 100644
--- a/src/examples/Package.java
+++ b/src/examples/Package.java
@@ -174,7 +174,7 @@ public class Package {
             }
             String clName = arg;
             if (clName.endsWith(JavaClass.EXTENSION)) {
-                clName = clName.substring(0, clName.length() - 6);
+                clName = clName.substring(0, clName.length() - JavaClass.EXTENSION.length());
             }
             clName = clName.replace('.', '/');
             try (final InputStream inputStream = classPath.getInputStream(clName)) {