From 1483867b9085c09de5271b752ad8f59b6540c890 Mon Sep 17 00:00:00 2001 From: Mark Roberts Date: Wed, 17 Jan 2024 08:39:59 -0800 Subject: [PATCH] Merge Apache commons-bcel-6.8.1 into our repo --- CONTRIBUTING.md | 5 +- NOTICE.txt | 2 +- README-codespecs.txt | 6 +- README.md | 7 +- RELEASE-NOTES.txt | 69 ++++++ pom.xml | 225 ++++++++--------- src/changes/changes.xml | 18 ++ src/changes/release-notes.vm | 4 +- src/conf/spotbugs-exclude-filter.xml | 69 +++++- src/examples/Mini/ASTFunDecl.java | 2 +- src/examples/ProxyCreator.java | 4 +- .../apache/bcel/classfile/AccessFlags.java | 226 ++++++++++++++++-- .../apache/bcel/classfile/CodeException.java | 2 +- .../org/apache/bcel/classfile/Constant.java | 21 +- .../apache/bcel/classfile/ConstantObject.java | 7 +- .../apache/bcel/classfile/ConstantUtf8.java | 9 +- .../java/org/apache/bcel/classfile/Field.java | 25 +- .../org/apache/bcel/classfile/JavaClass.java | 30 ++- .../org/apache/bcel/classfile/LineNumber.java | 2 +- .../org/apache/bcel/classfile/Method.java | 25 +- .../java/org/apache/bcel/classfile/Node.java | 2 +- .../apache/bcel/classfile/StackMapEntry.java | 8 +- .../org/apache/bcel/classfile/Visitor.java | 2 +- .../org/apache/bcel/generic/ArrayType.java | 2 +- .../org/apache/bcel/generic/ClassGen.java | 19 +- .../apache/bcel/generic/ExceptionThrower.java | 2 +- .../org/apache/bcel/generic/FieldGen.java | 27 +-- .../apache/bcel/generic/INVOKEDYNAMIC.java | 4 +- .../apache/bcel/generic/InstructionList.java | 3 + .../java/org/apache/bcel/generic/LDC.java | 5 + .../org/apache/bcel/generic/MethodGen.java | 23 +- .../org/apache/bcel/generic/ObjectType.java | 4 +- .../apache/bcel/generic/ReferenceType.java | 8 +- .../java/org/apache/bcel/generic/Type.java | 4 +- .../org/apache/bcel/util/BCELComparator.java | 23 +- .../apache/bcel/util/InstructionFinder.java | 2 +- .../bcel/verifier/GraphicalVerifier.java | 2 +- .../bcel/verifier/VerifierAppFrame.java | 2 +- .../apache/bcel/verifier/VerifyDialog.java | 4 +- .../bcel/verifier/statics/Pass2Verifier.java | 2 +- .../bcel/verifier/statics/Pass3aVerifier.java | 6 +- .../structurals/ExceptionHandler.java | 2 +- .../structurals/ExceptionHandlers.java | 2 +- .../structurals/ExecutionVisitor.java | 6 +- .../verifier/structurals/GenericArray.java | 2 +- .../structurals/InstConstraintVisitor.java | 10 +- .../verifier/structurals/Subroutines.java | 4 +- src/site/xdoc/download_bcel.xml | 26 +- src/site/xdoc/index.xml | 7 - .../EnclosingMethodAttributeTestCase.java | 1 + .../ConstantPoolModuleToStringTestCase.java | 12 +- .../bcel/classfile/ConstantPoolTestCase.java | 4 +- .../apache/bcel/classfile/ConstantTest.java | 38 +++ .../org/apache/bcel/classfile/FieldTest.java | 38 +++ .../apache/bcel/classfile/TestJira368.java | 4 +- .../org/apache/bcel/generic/ClassGenTest.java | 38 +++ .../org/apache/bcel/generic/FieldGenTest.java | 44 ++++ .../org/apache/bcel/generic/JavaHome.java | 2 +- .../org/apache/bcel/generic/TypeTestCase.java | 5 +- .../apache/bcel/util/BCELifierTestCase.java | 2 +- .../bcel/verifier/JiraBcel369TestCase.java | 2 +- .../bcel/verifier/JiraBcel370TestCase.java | 79 ++++++ .../statics/Pass3aVerifierTestCase.java | 135 +++++++++++ .../InstConstraintVisitorTestCase.java | 52 ++++ src/test/resources/com/foo/Foo.class | Bin 0 -> 770 bytes ...JavaLanguageParser$ClassBlockContext.class | Bin 0 -> 2624 bytes .../resources/ossfuzz/issue51980/Test.class | Bin 54 -> 0 bytes .../resources/ossfuzz/issue51989/Test.class | Bin 88 -> 0 bytes .../resources/ossfuzz/issue52168/Test.class | Bin 61 -> 0 bytes .../resources/ossfuzz/issue53543/Test.class | Bin 57 -> 0 bytes .../resources/ossfuzz/issue53544a/Test.class | Bin 49 -> 0 bytes .../resources/ossfuzz/issue53620/Test.class | Bin 227530 -> 0 bytes 72 files changed, 1085 insertions(+), 342 deletions(-) create mode 100644 src/test/java/org/apache/bcel/classfile/ConstantTest.java create mode 100644 src/test/java/org/apache/bcel/classfile/FieldTest.java create mode 100644 src/test/java/org/apache/bcel/generic/ClassGenTest.java create mode 100644 src/test/java/org/apache/bcel/generic/FieldGenTest.java create mode 100644 src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java create mode 100644 src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java create mode 100644 src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java create mode 100644 src/test/resources/com/foo/Foo.class create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser$ClassBlockContext.class delete mode 100644 src/test/resources/ossfuzz/issue51980/Test.class delete mode 100644 src/test/resources/ossfuzz/issue51989/Test.class delete mode 100644 src/test/resources/ossfuzz/issue52168/Test.class delete mode 100644 src/test/resources/ossfuzz/issue53543/Test.class delete mode 100644 src/test/resources/ossfuzz/issue53544a/Test.class delete mode 100644 src/test/resources/ossfuzz/issue53620/Test.class diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8986d489e4..cd33383389 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,13 +49,13 @@ Getting Started --------------- + Make sure you have a [JIRA account](https://issues.apache.org/jira/). -+ Make sure you have a [GitHub account](https://github.com/signup/free). ++ Make sure you have a [GitHub account](https://github.com/signup/free). This is not essential, but makes providing patches much easier. + If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons BCEL's scope. + Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist. + Clearly describe the issue including steps to reproduce when it is a bug. + Make sure you fill in the earliest version that you know has the issue. + Find the corresponding [repository on GitHub](https://github.com/apache/?query=commons-), -[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository. +[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository. If you don't have a GitHub account, you can still clone the Commons repository. Making Changes -------------- @@ -109,7 +109,6 @@ Additional Resources + [General GitHub documentation](https://help.github.com/) + [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/) + [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) -+ `#apache-commons` IRC channel on `irc.freenode.net` [cla]:https://www.apache.org/licenses/#clas [jira]:https://issues.apache.org/jira/browse/BCEL diff --git a/NOTICE.txt b/NOTICE.txt index b1184ffb0d..f3ff767ae2 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1,5 +1,5 @@ Apache Commons BCEL -Copyright 2004-2023 The Apache Software Foundation +Copyright 2004-2024 The Apache Software Foundation This product includes software developed at The Apache Software Foundation (https://www.apache.org/). diff --git a/README-codespecs.txt b/README-codespecs.txt index 47f8e257d2..75b02b4b78 100644 --- a/README-codespecs.txt +++ b/README-codespecs.txt @@ -11,10 +11,12 @@ To build this project --------------------- ``` -mvn verify +mvn -B clean verify ``` -The `.jar` file is found at, for example, `target/bcel-6.2.0.1.jar`. +(You may need to add -Drat.skip=true if you have local untracked files.) + +The `.jar` file will be found in the target subdirectory at, for example, `target/bcel-6.8.1.jar`. To update to a newer version of the upstream library diff --git a/README.md b/README.md index c4950df67a..4e10557350 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Apache Commons BCEL [![Java CI](https://github.com/apache/commons-bcel/actions/workflows/maven.yml/badge.svg)](https://github.com/apache/commons-bcel/actions/workflows/maven.yml) [![Coverage Status](https://codecov.io/gh/apache/commons-bcel/branch/master/graph/badge.svg)](https://app.codecov.io/gh/apache/commons-bcel) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.bcel/bcel/badge.svg?gav=true)](https://maven-badges.herokuapp.com/maven-central/org.apache.bcel/bcel/?gav=true) -[![Javadocs](https://javadoc.io/badge/org.apache.bcel/bcel/6.8.0.svg)](https://javadoc.io/doc/org.apache.bcel/bcel/6.8.0) +[![Javadocs](https://javadoc.io/badge/org.apache.bcel/bcel/6.8.1.svg)](https://javadoc.io/doc/org.apache.bcel/bcel/6.8.1) [![CodeQL](https://github.com/apache/commons-bcel/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/apache/commons-bcel/actions/workflows/codeql-analysis.yml) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/apache/commons-bcel/badge)](https://api.securityscorecards.dev/projects/github.com/apache/commons-bcel) @@ -57,7 +57,7 @@ Documentation More information can be found on the [Apache Commons BCEL homepage](https://commons.apache.org/proper/commons-bcel). The [Javadoc](https://commons.apache.org/proper/commons-bcel/apidocs) can be browsed. -Questions related to the usage of Apache Commons BCEL should be posted to the [user mailing list][ml]. +Questions related to the usage of Apache Commons BCEL should be posted to the [user mailing list](https://commons.apache.org/mail-lists.html). Getting the latest release -------------------------- @@ -69,7 +69,7 @@ Alternatively, you can pull it from the central Maven repositories: org.apache.bcel bcel - 6.8.0 + 6.8.1 ``` @@ -111,7 +111,6 @@ Additional Resources + [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/BCEL) + [Apache Commons Slack Channel](https://the-asf.slack.com/archives/C60NVB8AD) + [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) -+ `#apache-commons` IRC channel on `irc.freenode.org` Apache Commons Components ------------------------- diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index b1d0c2e91f..926f741a78 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,3 +1,72 @@ + Apache Commons BCEL + Version 6.8.1 + RELEASE NOTES + + +INTRODUCTION: + +The Apache Commons BCEL team is pleased to announce the release of +Apache Commons BCEL 6.8.1. + +The Byte Code Engineering Library (BCEL) is intended to give users a convenient +way to analyze, create, and manipulate compiled .class files. Classes are +represented by objects containing all the symbolic information of the given +class: methods, fields, and byte code instructions. + +Maintenance and bug fix release. + +FIXED BUGS: +=========== + +o Replace internal use of StringBuffer with StringBuilder. Thanks to Gary Gregory. +o BCEL-370: CONSTANT_Dynamic is not handled in LDC #254. Thanks to Gary Gregory. +o BCELComparator now uses generics. Thanks to Gary Gregory. +o Avoid NullPointerException in ClassGen.BCELComparator#equals() and ClassGen.BCELComparator#hashCode(). Thanks to Gary Gregory. +o Avoid NullPointerException in Constant.BCELComparator#equals() and Constant.BCELComparator#hashCode(). Thanks to Gary Gregory. +o Avoid NullPointerException in Field.BCELComparator#equals() and Field.BCELComparator#hashCode(). Thanks to Gary Gregory. +o Avoid NullPointerException in FieldGen.BCELComparator#equals() and FieldGen.BCELComparator#hashCode(). Thanks to Gary Gregory. +o Avoid NullPointerException in JavaClass.BCELComparator#equals() and JavaClass.BCELComparator#hashCode(). Thanks to Gary Gregory. +o Avoid NullPointerException in Method.BCELComparator#equals() and Method.BCELComparator#hashCode(). Thanks to Gary Gregory. +o Avoid NullPointerException in MethodGen.BCELComparator#equals() and MethodGen.BCELComparator#hashCode(). Thanks to Gary Gregory. + +CHANGES: +======== + +o Bump GitHub various actions for CI builds. Thanks to Dependabot. +o Bump jna.version from 5.13.0 to 5.14.0 #250. Thanks to Dependabot. +o Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.21 to 1.9.22 #252. Thanks to Dependabot. +o Bump org.apache.commons:commons-exec from 1.3 to 1.4.0 #255. Thanks to Dependabot. + + +Historical list of changes: https://commons.apache.org/proper/commons-bcelchanges-report.html + +For complete information on Apache Commons BCEL, including instructions on how to submit bug reports, +patches, or suggestions for improvement, see the Apache Commons BCEL website: + +https://commons.apache.org/proper/commons-bcel + +Download it from https://commons.apache.org/proper/commons-bcel/download_bcel.cgi + +Have fun! +-Apache Commons BCEL team + +Feedback +-------- + +Open source works best when you give feedback: + + https://commons.apache.org/bcel + +Please direct all bug reports to JIRA: + + https://issues.apache.org/jira/browse/BCEL + +Or subscribe to the commons-user mailing list + +The Apache Commons Team + +----------------------------------------------------------------------------- + Apache Commons BCEL Version 6.8.0 RELEASE NOTES diff --git a/pom.xml b/pom.xml index 7359e6fa74..5f0d666c18 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ org.apache.bcel bcel jar - 6.8.0 + 6.8.1 Apache Commons BCEL Apache Commons Bytecode Engineering Library @@ -47,10 +47,11 @@ 1.8 bcel org.apache.bcel - 6.8.0 + 6.8.1 + 6.8.2 true RC1 - 6.7.0 + 6.8.0 (Java 8 or above) https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-bcel scm:svn:https://dist.apache.org/repos/dist/dev/commons/${commons.componentid} @@ -62,7 +63,9 @@ BCEL 12314220 - 5.13.0 + 4.11.0 + 3.25.1 + 5.14.0 false @@ -79,121 +82,6 @@ https://github.com/apache/commons-bcel/actions - - - Dave Brosius - dbrosius - dbrosius at mebigfatguy.com - - - - Torsten Curdt - tcurdt - tcurdt at apache.org - ASF - http://www.apache.org/ - +1 - - - - Markus Dahm - mdahm - m.dahm at gmx.de - it-frameworksolutions - - - - Jason van Zyl - jason at zenplex.com - - - - ggregory - Gary Gregory - ggregory at apache.org - https://www.garygregory.com - The Apache Software Foundation - https://www.apache.org/ - - PMC Member - - America/New_York - - https://people.apache.org/~ggregory/img/garydgregory80.png - - - - - - - - - Enver Haase - enver at convergence.de - - - - David Dixon-Peugh - dixonpeugh at yahoo.com - - - - Patrick Beard - beard at netscape.com - - - - Conor MacNeill - conor at cortexbusiness.com.au - - - - Costin Manolache - cmanolache at yahoo.com - - - - Bill Pugh - bill.pugh at gmail.com - - - - First Hop Ltd / Torsten Rueger - - - - Jérôme Leroux - - - - Mark Roberts - - - - Sam Yoon - - - - Arturo Bernal - - - - - - - BCEL User List - user-subscribe@commons.apache.org - user-unsubscribe@commons.apache.org - https://mail-archives.apache.org/mod_mbox/commons-user/ - - - BCEL Developer List - dev-subscribe@commons.apache.org - dev-unsubscribe@commons.apache.org - https://mail-archives.apache.org/mod_mbox/commons-dev/ - - - jira https://issues.apache.org/jira/browse/BCEL @@ -330,8 +218,6 @@ Normal Default src/conf/spotbugs-exclude-filter.xml - - 9 @@ -452,6 +338,18 @@ junit-jupiter test + + org.mockito + mockito-core + ${mockito.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + net.java.dev.jna jna @@ -485,7 +383,7 @@ org.apache.commons commons-exec - 1.3 + 1.4.0 test @@ -512,7 +410,7 @@ org.jetbrains.kotlin kotlin-stdlib - 1.9.21 + 1.9.22 test @@ -623,4 +521,85 @@ + + + Dave Brosius + dbrosius + dbrosius at mebigfatguy.com + + + Torsten Curdt + tcurdt + tcurdt at apache.org + ASF + http://www.apache.org/ + +1 + + + Markus Dahm + mdahm + m.dahm at gmx.de + it-frameworksolutions + + + Jason van Zyl + jason at zenplex.com + + + ggregory + Gary Gregory + ggregory at apache.org + https://www.garygregory.com + The Apache Software Foundation + https://www.apache.org/ + + PMC Member + + America/New_York + + https://people.apache.org/~ggregory/img/garydgregory80.png + + + + + + Enver Haase + enver at convergence.de + + + David Dixon-Peugh + dixonpeugh at yahoo.com + + + Patrick Beard + beard at netscape.com + + + Conor MacNeill + conor at cortexbusiness.com.au + + + Costin Manolache + cmanolache at yahoo.com + + + Bill Pugh + bill.pugh at gmail.com + + + First Hop Ltd / Torsten Rueger + + + Jérôme Leroux + + + Mark Roberts + + + Sam Yoon + + + Arturo Bernal + + diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9d8828f65c..73c30411ee 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -64,6 +64,24 @@ The type attribute can be add,update,fix,remove. --> + + + Replace internal use of StringBuffer with StringBuilder. + CONSTANT_Dynamic is not handled in LDC #254. + BCELComparator now uses generics. + Avoid NullPointerException in ClassGen.BCELComparator#equals() and ClassGen.BCELComparator#hashCode(). + Avoid NullPointerException in Constant.BCELComparator#equals() and Constant.BCELComparator#hashCode(). + Avoid NullPointerException in Field.BCELComparator#equals() and Field.BCELComparator#hashCode(). + Avoid NullPointerException in FieldGen.BCELComparator#equals() and FieldGen.BCELComparator#hashCode(). + Avoid NullPointerException in JavaClass.BCELComparator#equals() and JavaClass.BCELComparator#hashCode(). + Avoid NullPointerException in Method.BCELComparator#equals() and Method.BCELComparator#hashCode(). + Avoid NullPointerException in MethodGen.BCELComparator#equals() and MethodGen.BCELComparator#hashCode(). + + Bump GitHub various actions for CI builds. + Bump jna.version from 5.13.0 to 5.14.0 #250. + Bump org.jetbrains.kotlin:kotlin-stdlib from 1.9.21 to 1.9.22 #252. + Bump org.apache.commons:commons-exec from 1.3 to 1.4.0 #255. + Add and use InvalidMethodSignatureException extending ClassFormatException. diff --git a/src/changes/release-notes.vm b/src/changes/release-notes.vm index 97122d5e2d..7d1bcc9a02 100644 --- a/src/changes/release-notes.vm +++ b/src/changes/release-notes.vm @@ -23,12 +23,12 @@ INTRODUCTION: The ${developmentTeam} is pleased to announce the release of -${project.name} ${version}! +${project.name} ${version}. The Byte Code Engineering Library (BCEL) is intended to give users a convenient way to analyze, create, and manipulate compiled .class files. Classes are represented by objects containing all the symbolic information of the given -class: methods, fields and byte code instructions. +class: methods, fields, and byte code instructions. ##$introduction.replaceAll("(? - - - + + + + + + + + + + + + + + + + @@ -91,4 +110,48 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/examples/Mini/ASTFunDecl.java b/src/examples/Mini/ASTFunDecl.java index 6002a168c9..2a3fadf591 100644 --- a/src/examples/Mini/ASTFunDecl.java +++ b/src/examples/Mini/ASTFunDecl.java @@ -317,7 +317,7 @@ public void code(final PrintWriter out) { } if (!ignore) { - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); body.code(buf); out.println(getVarDecls()); diff --git a/src/examples/ProxyCreator.java b/src/examples/ProxyCreator.java index 4f80fbcf8c..995f607191 100644 --- a/src/examples/ProxyCreator.java +++ b/src/examples/ProxyCreator.java @@ -34,7 +34,7 @@ import org.apache.bcel.generic.Type; /** - * Dynamically creates and uses a proxy for {@code java.awt.event.ActionListener} via the class loader mechanism if + * Dynamically creates and uses a proxy for {@link java.awt.event.ActionListener} via the class loader mechanism if * called with * *
@@ -45,7 +45,7 @@
  * however in big ugly class name, so for many cases it will be more sufficient to put some clever creation code into
  * the class loader.
  * 

- * This is comparable to the mechanism provided via {@code java.lang.reflect.Proxy}, but much more flexible. + * This is comparable to the mechanism provided via {@link java.lang.reflect.Proxy}, but much more flexible. *

* * @see org.apache.bcel.util.JavaWrapper diff --git a/src/main/java/org/apache/bcel/classfile/AccessFlags.java b/src/main/java/org/apache/bcel/classfile/AccessFlags.java index 6310b7e310..c5946f9483 100644 --- a/src/main/java/org/apache/bcel/classfile/AccessFlags.java +++ b/src/main/java/org/apache/bcel/classfile/AccessFlags.java @@ -24,22 +24,31 @@ public abstract class AccessFlags { /** - * @deprecated (since 6.0) will be made private; do not access directly, use getter/setter + * Access flags. + * + * @deprecated (since 6.0) will be made private; do not access directly, use getter/setter. */ @java.lang.Deprecated protected int access_flags; // TODO not used externally at present + /** + * Constructs a new instance. + */ public AccessFlags() { } /** - * @param a initial access flags + * Constructs a new instance. + * + * @param accessFlags initial access flags. */ - public AccessFlags(final int a) { - access_flags = a; + public AccessFlags(final int accessFlags) { + access_flags = accessFlags; } /** + * Gets access flags. + * * @return Access flags of the object aka. "modifiers". */ public final int getAccessFlags() { @@ -47,142 +56,303 @@ public final int getAccessFlags() { } /** - * @return Access flags of the object aka. "modifiers". + * Gets access flags. + * + * @return Access flags of the object also known as modifiers. */ public final int getModifiers() { return access_flags; } + /** + * Tests whether the abstract bit is on. + * + * @return whether the abstract bit is on. + */ public final boolean isAbstract() { - return (access_flags & Const.ACC_ABSTRACT) != 0; + return test(Const.ACC_ABSTRACT); } + /** + * Sets the abstract bit. + * + * @param flag The new value. + */ public final void isAbstract(final boolean flag) { setFlag(Const.ACC_ABSTRACT, flag); } + /** + * Tests whether the annotation bit is on. + * + * @return whether the annotation bit is on. + */ public final boolean isAnnotation() { - return (access_flags & Const.ACC_ANNOTATION) != 0; + return test(Const.ACC_ANNOTATION); } + /** + * Sets the annotation bit. + * + * @param flag The new value. + */ public final void isAnnotation(final boolean flag) { setFlag(Const.ACC_ANNOTATION, flag); } - + /** + * Tests whether the enum bit is on. + * + * @return whether the enum bit is on. + */ public final boolean isEnum() { - return (access_flags & Const.ACC_ENUM) != 0; + return test(Const.ACC_ENUM); } + /** + * Sets the enum bit. + * + * @param flag The new value. + */ public final void isEnum(final boolean flag) { setFlag(Const.ACC_ENUM, flag); } + /** + * Tests whether the final bit is on. + * + * @return whether the final bit is on. + */ public final boolean isFinal() { - return (access_flags & Const.ACC_FINAL) != 0; + return test(Const.ACC_FINAL); } + /** + * Sets the final bit. + * + * @param flag The new value. + */ public final void isFinal(final boolean flag) { setFlag(Const.ACC_FINAL, flag); } + /** + * Tests whether the interface bit is on. + * + * @return whether the interface bit is on. + */ public final boolean isInterface() { - return (access_flags & Const.ACC_INTERFACE) != 0; + return test(Const.ACC_INTERFACE); } + /** + * Sets the interface bit. + * + * @param flag The new value. + */ public final void isInterface(final boolean flag) { setFlag(Const.ACC_INTERFACE, flag); } + /** + * Tests whether the native bit is on. + * + * @return whether the native bit is on. + */ public final boolean isNative() { - return (access_flags & Const.ACC_NATIVE) != 0; + return test(Const.ACC_NATIVE); } + /** + * Sets the native bit. + * + * @param flag The new value. + */ public final void isNative(final boolean flag) { setFlag(Const.ACC_NATIVE, flag); } + /** + * Tests whether the private bit is on. + * + * @return whether the private bit is on. + */ public final boolean isPrivate() { - return (access_flags & Const.ACC_PRIVATE) != 0; + return test(Const.ACC_PRIVATE); } + /** + * Sets the private bit. + * + * @param flag The new value. + */ public final void isPrivate(final boolean flag) { setFlag(Const.ACC_PRIVATE, flag); } + /** + * Tests whether the protected bit is on. + * + * @return whether the protected bit is on. + */ public final boolean isProtected() { - return (access_flags & Const.ACC_PROTECTED) != 0; + return test(Const.ACC_PROTECTED); } + /** + * Sets the protected bit. + * + * @param flag The new value. + */ public final void isProtected(final boolean flag) { setFlag(Const.ACC_PROTECTED, flag); } + /** + * Tests whether the public bit is on. + * + * @return whether the public bit is on. + */ public final boolean isPublic() { - return (access_flags & Const.ACC_PUBLIC) != 0; + return test(Const.ACC_PUBLIC); } + /** + * Sets the public bit. + * + * @param flag The new value. + */ public final void isPublic(final boolean flag) { setFlag(Const.ACC_PUBLIC, flag); } + /** + * Tests whether the static bit is on. + * + * @return whether the static bit is on. + */ public final boolean isStatic() { - return (access_flags & Const.ACC_STATIC) != 0; + return test(Const.ACC_STATIC); } + /** + * Sets the static bit. + * + * @param flag The new value. + */ public final void isStatic(final boolean flag) { setFlag(Const.ACC_STATIC, flag); } + /** + * Tests whether the strict bit is on. + * + * @return whether the strict bit is on. + */ public final boolean isStrictfp() { - return (access_flags & Const.ACC_STRICT) != 0; + return test(Const.ACC_STRICT); } + /** + * Sets the strict bit. + * + * @param flag The new value. + */ public final void isStrictfp(final boolean flag) { setFlag(Const.ACC_STRICT, flag); } + /** + * Tests whether the synchronized bit is on. + * + * @return whether the synchronized bit is on. + */ public final boolean isSynchronized() { - return (access_flags & Const.ACC_SYNCHRONIZED) != 0; + return test(Const.ACC_SYNCHRONIZED); } + /** + * Sets the synchronized bit. + * + * @param flag The new value. + */ public final void isSynchronized(final boolean flag) { setFlag(Const.ACC_SYNCHRONIZED, flag); } + /** + * Tests whether the synthetic bit is on. + * + * @return whether the synthetic bit is on. + */ public final boolean isSynthetic() { - return (access_flags & Const.ACC_SYNTHETIC) != 0; + return test(Const.ACC_SYNTHETIC); } + /** + * Sets the synthetic bit. + * + * @param flag The new value. + */ public final void isSynthetic(final boolean flag) { setFlag(Const.ACC_SYNTHETIC, flag); } + /** + * Tests whether the transient bit is on. + * + * @return whether the varargs bit is on. + */ public final boolean isTransient() { - return (access_flags & Const.ACC_TRANSIENT) != 0; + return test(Const.ACC_TRANSIENT); } + /** + * Sets the varargs bit. + * + * @param flag The new value. + */ public final void isTransient(final boolean flag) { setFlag(Const.ACC_TRANSIENT, flag); } + /** + * Tests whether the varargs bit is on. + * + * @return whether the varargs bit is on. + */ public final boolean isVarArgs() { - return (access_flags & Const.ACC_VARARGS) != 0; + return test(Const.ACC_VARARGS); } + /** + * Sets the varargs bit. + * + * @param flag The new value. + */ public final void isVarArgs(final boolean flag) { setFlag(Const.ACC_VARARGS, flag); } + /** + * Tests whether the volatile bit is on. + * + * @return whether the volatile bit is on. + */ public final boolean isVolatile() { - return (access_flags & Const.ACC_VOLATILE) != 0; + return test(Const.ACC_VOLATILE); } + /** + * Sets the volatile bit. + * + * @param flag The new value. + */ public final void isVolatile(final boolean flag) { setFlag(Const.ACC_VOLATILE, flag); } /** - * Sets access flags aka "modifiers". + * Sets access flags also known as modifiers. * * @param accessFlags Access flags of the object. */ @@ -208,4 +378,14 @@ private void setFlag(final int flag, final boolean set) { public final void setModifiers(final int accessFlags) { setAccessFlags(accessFlags); } + + /** + * Tests whether the bit is on. + * + * @param test the bit to test. + * @return whether the bit is on. + */ + private boolean test(final short test) { + return (access_flags & test) != 0; + } } diff --git a/src/main/java/org/apache/bcel/classfile/CodeException.java b/src/main/java/org/apache/bcel/classfile/CodeException.java index d5b16ce6ed..5171bcacf5 100644 --- a/src/main/java/org/apache/bcel/classfile/CodeException.java +++ b/src/main/java/org/apache/bcel/classfile/CodeException.java @@ -60,7 +60,7 @@ public final class CodeException implements Cloneable, Node, Constants { /** Range in the code the exception handler. */ private int startPc; - /** active. startPc is inclusive, endPc exclusive. */ + /** Active. startPc is inclusive, endPc exclusive. */ private int endPc; /** diff --git a/src/main/java/org/apache/bcel/classfile/Constant.java b/src/main/java/org/apache/bcel/classfile/Constant.java index a70400cd72..6ed876d058 100644 --- a/src/main/java/org/apache/bcel/classfile/Constant.java +++ b/src/main/java/org/apache/bcel/classfile/Constant.java @@ -30,26 +30,23 @@ */ public abstract class Constant implements Cloneable, Node { - private static BCELComparator bcelComparator = new BCELComparator() { + private static BCELComparator bcelComparator = new BCELComparator() { @Override - public boolean equals(final Object o1, final Object o2) { - final Constant THIS = (Constant) o1; - final Constant THAT = (Constant) o2; - return Objects.equals(THIS.toString(), THAT.toString()); + public boolean equals(final Constant a, final Constant b) { + return a == b || a != null && b != null && Objects.equals(a.toString(), b.toString()); } @Override - public int hashCode(final Object o) { - final Constant THIS = (Constant) o; - return THIS.toString().hashCode(); + public int hashCode(final Constant o) { + return o != null ? Objects.hashCode(o.toString()) : 0; } }; /** - * @return Comparison strategy object + * @return Comparison strategy object. */ - public static BCELComparator getComparator() { + public static BCELComparator getComparator() { return bcelComparator; } @@ -107,7 +104,7 @@ public static Constant readConstant(final DataInput dataInput) throws IOExceptio /** * @param comparator Comparison strategy object */ - public static void setComparator(final BCELComparator comparator) { + public static void setComparator(final BCELComparator comparator) { bcelComparator = comparator; } @@ -168,7 +165,7 @@ public Constant copy() { */ @Override public boolean equals(final Object obj) { - return bcelComparator.equals(this, obj); + return obj instanceof Constant && bcelComparator.equals(this, (Constant) obj); } /** diff --git a/src/main/java/org/apache/bcel/classfile/ConstantObject.java b/src/main/java/org/apache/bcel/classfile/ConstantObject.java index e15699f03e..64ae7cd950 100644 --- a/src/main/java/org/apache/bcel/classfile/ConstantObject.java +++ b/src/main/java/org/apache/bcel/classfile/ConstantObject.java @@ -24,7 +24,10 @@ public interface ConstantObject { /** - * @return object representing the constant, e.g., Long for ConstantLong + * Gets the object representing the constant, e.g., Long for ConstantLong. + * + * @param constantPool the constant. + * @return object representing the constant, e.g., Long for ConstantLong. */ - Object getConstantValue(ConstantPool cp); + Object getConstantValue(ConstantPool constantPool); } diff --git a/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java b/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java index 51a843c861..7ac35fb5a7 100644 --- a/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java +++ b/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java @@ -112,6 +112,11 @@ static synchronized void clearStats() { hits = considered = skipped = created = 0; } + // Avoid Spotbugs complaint about Write to static field + private static void countCreated() { + created++; + } + /** * Gets a new or cached instance of the given value. *

@@ -198,7 +203,7 @@ public ConstantUtf8(final ConstantUtf8 constantUtf8) { ConstantUtf8(final DataInput dataInput) throws IOException { super(Const.CONSTANT_Utf8); value = dataInput.readUTF(); - created++; + countCreated(); } /** @@ -207,7 +212,7 @@ public ConstantUtf8(final ConstantUtf8 constantUtf8) { public ConstantUtf8(final String value) { super(Const.CONSTANT_Utf8); this.value = Objects.requireNonNull(value, "value"); - created++; + countCreated(); } /** diff --git a/src/main/java/org/apache/bcel/classfile/Field.java b/src/main/java/org/apache/bcel/classfile/Field.java index e7b967b8df..a7f002e0fa 100644 --- a/src/main/java/org/apache/bcel/classfile/Field.java +++ b/src/main/java/org/apache/bcel/classfile/Field.java @@ -37,19 +37,16 @@ public final class Field extends FieldOrMethod { */ public static final Field[] EMPTY_ARRAY = {}; - private static BCELComparator bcelComparator = new BCELComparator() { + private static BCELComparator bcelComparator = new BCELComparator() { @Override - public boolean equals(final Object o1, final Object o2) { - final Field THIS = (Field) o1; - final Field THAT = (Field) o2; - return Objects.equals(THIS.getName(), THAT.getName()) && Objects.equals(THIS.getSignature(), THAT.getSignature()); + public boolean equals(final Field a, final Field b) { + return a == b || a != null && b != null && Objects.equals(a.getName(), b.getName()) && Objects.equals(a.getSignature(), b.getSignature()); } @Override - public int hashCode(final Object o) { - final Field THIS = (Field) o; - return THIS.getSignature().hashCode() ^ THIS.getName().hashCode(); + public int hashCode(final Field o) { + return o != null ? Objects.hash(o.getSignature(), o.getName()) : 0; } }; @@ -59,23 +56,23 @@ public int hashCode(final Object o) { static final Field[] EMPTY_FIELD_ARRAY = {}; /** - * @return Comparison strategy object + * @return Comparison strategy object. */ - public static BCELComparator getComparator() { + public static BCELComparator getComparator() { return bcelComparator; } /** - * @param comparator Comparison strategy object + * @param comparator Comparison strategy object. */ - public static void setComparator(final BCELComparator comparator) { + public static void setComparator(final BCELComparator comparator) { bcelComparator = comparator; } /** * Constructs object from file stream. * - * @param file Input stream + * @param file Input stream. */ Field(final DataInput file, final ConstantPool constantPool) throws IOException, ClassFormatException { super(file, constantPool); @@ -128,7 +125,7 @@ public Field copy(final ConstantPool constantPool) { */ @Override public boolean equals(final Object obj) { - return bcelComparator.equals(this, obj); + return obj instanceof Field && bcelComparator.equals(this, (Field) obj); } /** diff --git a/src/main/java/org/apache/bcel/classfile/JavaClass.java b/src/main/java/org/apache/bcel/classfile/JavaClass.java index 210441f9ff..5bcd5c7e2c 100644 --- a/src/main/java/org/apache/bcel/classfile/JavaClass.java +++ b/src/main/java/org/apache/bcel/classfile/JavaClass.java @@ -65,19 +65,17 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl public static final byte FILE = 2; public static final byte ZIP = 3; private static final boolean debug = Boolean.getBoolean("JavaClass.debug"); // Debugging on/off - private static BCELComparator bcelComparator = new BCELComparator() { + + private static BCELComparator bcelComparator = new BCELComparator() { @Override - public boolean equals(final Object o1, final Object o2) { - final JavaClass THIS = (JavaClass) o1; - final JavaClass THAT = (JavaClass) o2; - return Objects.equals(THIS.getClassName(), THAT.getClassName()); + public boolean equals(final JavaClass a, final JavaClass b) { + return a == b || a != null && b != null && Objects.equals(a.getClassName(), b.getClassName()); } @Override - public int hashCode(final Object o) { - final JavaClass THIS = (JavaClass) o; - return THIS.getClassName().hashCode(); + public int hashCode(final JavaClass o) { + return o != null ? Objects.hashCode(o.getClassName()) : 0; } }; @@ -91,9 +89,9 @@ static void Debug(final String str) { } /** - * @return Comparison strategy object + * @return Comparison strategy object. */ - public static BCELComparator getComparator() { + public static BCELComparator getComparator() { return bcelComparator; } @@ -107,9 +105,9 @@ private static String indent(final Object obj) { } /** - * @param comparator Comparison strategy object + * @param comparator Comparison strategy object. */ - public static void setComparator(final BCELComparator comparator) { + public static void setComparator(final BCELComparator comparator) { bcelComparator = comparator; } @@ -391,7 +389,7 @@ public void dump(final String fileName) throws IOException { */ @Override public boolean equals(final Object obj) { - return bcelComparator.equals(this, obj); + return obj instanceof JavaClass && bcelComparator.equals(this, (JavaClass) obj); } /** @@ -634,7 +632,7 @@ public String getSourceFilePath() { } /** - * @return the superclass for this JavaClass object, or null if this is java.lang.Object + * @return the superclass for this JavaClass object, or null if this is {@link Object} * @throws ClassNotFoundException if the superclass can't be found */ public JavaClass getSuperClass() throws ClassNotFoundException { @@ -658,8 +656,8 @@ public JavaClass[] getSuperClasses() throws ClassNotFoundException { } /** - * returns the super class name of this class. In the case that this class is java.lang.Object, it will return itself - * (java.lang.Object). This is probably incorrect but isn't fixed at this time to not break existing clients. + * returns the super class name of this class. In the case that this class is {@link Object}, it will return itself + * ({@link Object}). This is probably incorrect but isn't fixed at this time to not break existing clients. * * @return Superclass name. */ diff --git a/src/main/java/org/apache/bcel/classfile/LineNumber.java b/src/main/java/org/apache/bcel/classfile/LineNumber.java index 4f0cbcd4e7..c09c29ea43 100644 --- a/src/main/java/org/apache/bcel/classfile/LineNumber.java +++ b/src/main/java/org/apache/bcel/classfile/LineNumber.java @@ -35,7 +35,7 @@ public final class LineNumber implements Cloneable, Node { /** Program Counter (PC) corresponds to line */ private int startPc; - /** number in source file */ + /** Number in source file */ private int lineNumber; /** diff --git a/src/main/java/org/apache/bcel/classfile/Method.java b/src/main/java/org/apache/bcel/classfile/Method.java index b9c1e36829..84d7e4751d 100644 --- a/src/main/java/org/apache/bcel/classfile/Method.java +++ b/src/main/java/org/apache/bcel/classfile/Method.java @@ -36,19 +36,16 @@ public final class Method extends FieldOrMethod { */ public static final Method[] EMPTY_ARRAY = {}; - private static BCELComparator bcelComparator = new BCELComparator() { + private static BCELComparator bcelComparator = new BCELComparator() { @Override - public boolean equals(final Object o1, final Object o2) { - final Method THIS = (Method) o1; - final Method THAT = (Method) o2; - return Objects.equals(THIS.getName(), THAT.getName()) && Objects.equals(THIS.getSignature(), THAT.getSignature()); + public boolean equals(final Method a, final Method b) { + return a == b || a != null && b != null && Objects.equals(a.getName(), b.getName()) && Objects.equals(a.getSignature(), b.getSignature()); } @Override - public int hashCode(final Object o) { - final Method THIS = (Method) o; - return THIS.getSignature().hashCode() ^ THIS.getName().hashCode(); + public int hashCode(final Method o) { + return o != null ? Objects.hash(o.getSignature(), o.getName()) : 0; } }; @@ -58,20 +55,20 @@ public int hashCode(final Object o) { static final Method[] EMPTY_METHOD_ARRAY = {}; /** - * @return Comparison strategy object + * @return Comparison strategy object. */ - public static BCELComparator getComparator() { + public static BCELComparator getComparator() { return bcelComparator; } /** - * @param comparator Comparison strategy object + * @param comparator Comparison strategy object. */ - public static void setComparator(final BCELComparator comparator) { + public static void setComparator(final BCELComparator comparator) { bcelComparator = comparator; } - // annotations defined on the parameters of a method + /** Annotations defined on the parameters of a method. */ private ParameterAnnotationEntry[] parameterAnnotationEntries; /** @@ -138,7 +135,7 @@ public Method copy(final ConstantPool constantPool) { */ @Override public boolean equals(final Object obj) { - return bcelComparator.equals(this, obj); + return obj instanceof Method && bcelComparator.equals(this, (Method) obj); } /** diff --git a/src/main/java/org/apache/bcel/classfile/Node.java b/src/main/java/org/apache/bcel/classfile/Node.java index 1fecc0cf9e..51a9bfbec3 100644 --- a/src/main/java/org/apache/bcel/classfile/Node.java +++ b/src/main/java/org/apache/bcel/classfile/Node.java @@ -21,5 +21,5 @@ */ public interface Node { - void accept(Visitor obj); + void accept(Visitor visitor); } diff --git a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java index 5b8a7f5149..4afe9c0f4f 100644 --- a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java +++ b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java @@ -71,9 +71,7 @@ public final class StackMapEntry implements Node, Cloneable { } else if (frameType == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) { byteCodeOffset = dataInput.readUnsignedShort(); typesOfStackItems = new StackMapType[] { new StackMapType(dataInput, constantPool) }; - } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX) { - byteCodeOffset = dataInput.readUnsignedShort(); - } else if (frameType == Const.SAME_FRAME_EXTENDED) { + } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX || frameType == Const.SAME_FRAME_EXTENDED) { byteCodeOffset = dataInput.readUnsignedShort(); } else if (frameType >= Const.APPEND_FRAME && frameType <= Const.APPEND_FRAME_MAX) { byteCodeOffset = dataInput.readUnsignedShort(); @@ -186,9 +184,7 @@ public void dump(final DataOutputStream file) throws IOException { } else if (frameType == Const.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) { file.writeShort(byteCodeOffset); typesOfStackItems[0].dump(file); - } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX) { - file.writeShort(byteCodeOffset); - } else if (frameType == Const.SAME_FRAME_EXTENDED) { + } else if (frameType >= Const.CHOP_FRAME && frameType <= Const.CHOP_FRAME_MAX || frameType == Const.SAME_FRAME_EXTENDED) { file.writeShort(byteCodeOffset); } else if (frameType >= Const.APPEND_FRAME && frameType <= Const.APPEND_FRAME_MAX) { file.writeShort(byteCodeOffset); diff --git a/src/main/java/org/apache/bcel/classfile/Visitor.java b/src/main/java/org/apache/bcel/classfile/Visitor.java index 9a3388cf0d..4f4b5c2116 100644 --- a/src/main/java/org/apache/bcel/classfile/Visitor.java +++ b/src/main/java/org/apache/bcel/classfile/Visitor.java @@ -230,7 +230,7 @@ default void visitNestMembers(final NestMembers obj) { * @param obj object to visit * @since 6.8.0 */ - default void visitStackMapType(StackMapType obj) { + default void visitStackMapType(final StackMapType obj) { // empty } diff --git a/src/main/java/org/apache/bcel/generic/ArrayType.java b/src/main/java/org/apache/bcel/generic/ArrayType.java index 6b846a3ccd..d0c7501b32 100644 --- a/src/main/java/org/apache/bcel/generic/ArrayType.java +++ b/src/main/java/org/apache/bcel/generic/ArrayType.java @@ -39,7 +39,7 @@ public ArrayType(final byte type, final int dimensions) { /** * Convenience constructor for reference array type, e.g. Object[] * - * @param className complete name of class (java.lang.String, e.g.) + * @param className complete name of class ({@link String}, for example) * @param dimensions array dimensions */ public ArrayType(final String className, final int dimensions) { diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java index cb4ecb5e7d..b612050a93 100644 --- a/src/main/java/org/apache/bcel/generic/ClassGen.java +++ b/src/main/java/org/apache/bcel/generic/ClassGen.java @@ -44,33 +44,30 @@ */ public class ClassGen extends AccessFlags implements Cloneable { - private static BCELComparator bcelComparator = new BCELComparator() { + private static BCELComparator bcelComparator = new BCELComparator() { @Override - public boolean equals(final Object o1, final Object o2) { - final ClassGen THIS = (ClassGen) o1; - final ClassGen THAT = (ClassGen) o2; - return Objects.equals(THIS.getClassName(), THAT.getClassName()); + public boolean equals(final ClassGen a, final ClassGen b) { + return a == b || a != null && b != null && Objects.equals(a.getClassName(), b.getClassName()); } @Override - public int hashCode(final Object o) { - final ClassGen THIS = (ClassGen) o; - return THIS.getClassName().hashCode(); + public int hashCode(final ClassGen o) { + return o != null ? Objects.hashCode(o.getClassName()) : 0; } }; /** * @return Comparison strategy object */ - public static BCELComparator getComparator() { + public static BCELComparator getComparator() { return bcelComparator; } /** * @param comparator Comparison strategy object */ - public static void setComparator(final BCELComparator comparator) { + public static void setComparator(final BCELComparator comparator) { bcelComparator = comparator; } @@ -279,7 +276,7 @@ public Method containsMethod(final String name, final String signature) { */ @Override public boolean equals(final Object obj) { - return bcelComparator.equals(this, obj); + return obj instanceof ClassGen && bcelComparator.equals(this, (ClassGen) obj); } // J5TODO: Should we make calling unpackAnnotations() lazy and put it in here? diff --git a/src/main/java/org/apache/bcel/generic/ExceptionThrower.java b/src/main/java/org/apache/bcel/generic/ExceptionThrower.java index 8fa73e76f9..b21c620135 100644 --- a/src/main/java/org/apache/bcel/generic/ExceptionThrower.java +++ b/src/main/java/org/apache/bcel/generic/ExceptionThrower.java @@ -18,7 +18,7 @@ /** * Denote an instruction that may throw a run-time or a linking exception (or both) during execution. This is not quite - * the truth as such; because all instructions may throw an java.lang.VirtualMachineError. These exceptions are omitted. + * the truth as such; because all instructions may throw a {@link VirtualMachineError}. These exceptions are omitted. * * The Lava Language Specification specifies exactly which RUN-TIME and which LINKING exceptions each * instruction may throw which is reflected by the implementers. Due to the structure of the JVM specification, it may diff --git a/src/main/java/org/apache/bcel/generic/FieldGen.java b/src/main/java/org/apache/bcel/generic/FieldGen.java index 052ab4c4ed..d964d15bb5 100644 --- a/src/main/java/org/apache/bcel/generic/FieldGen.java +++ b/src/main/java/org/apache/bcel/generic/FieldGen.java @@ -40,33 +40,30 @@ */ public class FieldGen extends FieldGenOrMethodGen { - private static BCELComparator bcelComparator = new BCELComparator() { + private static BCELComparator bcelComparator = new BCELComparator() { @Override - public boolean equals(final Object o1, final Object o2) { - final FieldGen THIS = (FieldGen) o1; - final FieldGen THAT = (FieldGen) o2; - return Objects.equals(THIS.getName(), THAT.getName()) && Objects.equals(THIS.getSignature(), THAT.getSignature()); + public boolean equals(final FieldGen a, final FieldGen b) { + return a == b || a != null && b != null && Objects.equals(a.getName(), b.getName()) && Objects.equals(a.getSignature(), b.getSignature()); } @Override - public int hashCode(final Object o) { - final FieldGen THIS = (FieldGen) o; - return THIS.getSignature().hashCode() ^ THIS.getName().hashCode(); + public int hashCode(final FieldGen o) { + return o != null ? Objects.hash(o.getSignature(), o.getName()) : 0; } }; /** - * @return Comparison strategy object + * @return Comparison strategy object. */ - public static BCELComparator getComparator() { + public static BCELComparator getComparator() { return bcelComparator; } /** - * @param comparator Comparison strategy object + * @param comparator Comparison strategy object. */ - public static void setComparator(final BCELComparator comparator) { + public static void setComparator(final BCELComparator comparator) { bcelComparator = comparator; } @@ -77,8 +74,8 @@ public static void setComparator(final BCELComparator comparator) { /** * Instantiate from existing field. * - * @param field Field object - * @param cp constant pool (must contain the same entries as the field's constant pool) + * @param field Field object. + * @param cp constant pool (must contain the same entries as the field's constant pool). */ public FieldGen(final Field field, final ConstantPoolGen cp) { this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp); @@ -183,7 +180,7 @@ public FieldGen copy(final ConstantPoolGen cp) { */ @Override public boolean equals(final Object obj) { - return bcelComparator.equals(this, obj); + return obj instanceof FieldGen && bcelComparator.equals(this, (FieldGen) obj); } /** diff --git a/src/main/java/org/apache/bcel/generic/INVOKEDYNAMIC.java b/src/main/java/org/apache/bcel/generic/INVOKEDYNAMIC.java index dd935b79c7..d849de4bb7 100644 --- a/src/main/java/org/apache/bcel/generic/INVOKEDYNAMIC.java +++ b/src/main/java/org/apache/bcel/generic/INVOKEDYNAMIC.java @@ -98,11 +98,11 @@ public Class[] getExceptions() { } /** - * Since InvokeDynamic doesn't refer to a reference type, just return java.lang.Object, as that is the only type we can + * Since InvokeDynamic doesn't refer to a reference type, just return {@link Object}, as that is the only type we can * say for sure the reference will be. * * @param cpg the ConstantPoolGen used to create the instruction - * @return an ObjectType for java.lang.Object + * @return an ObjectType for {@link Object} * @since 6.1 */ @Override diff --git a/src/main/java/org/apache/bcel/generic/InstructionList.java b/src/main/java/org/apache/bcel/generic/InstructionList.java index c373e3b3f5..ca053e4418 100644 --- a/src/main/java/org/apache/bcel/generic/InstructionList.java +++ b/src/main/java/org/apache/bcel/generic/InstructionList.java @@ -1129,6 +1129,9 @@ public void setPositions(final boolean check) { // called by code in other packa case Const.LOOKUPSWITCH: maxAdditionalBytes += 3; break; + default: + // TODO should this be an error? + break; } index += i.getLength(); } diff --git a/src/main/java/org/apache/bcel/generic/LDC.java b/src/main/java/org/apache/bcel/generic/LDC.java index 5969b15782..559d110851 100644 --- a/src/main/java/org/apache/bcel/generic/LDC.java +++ b/src/main/java/org/apache/bcel/generic/LDC.java @@ -89,6 +89,8 @@ public Type getType(final ConstantPoolGen cpg) { return Type.INT; case org.apache.bcel.Const.CONSTANT_Class: return Type.CLASS; + case org.apache.bcel.Const.CONSTANT_Dynamic: + return Type.OBJECT; default: // Never reached throw new IllegalArgumentException("Unknown or invalid constant type at " + super.getIndex()); } @@ -109,6 +111,9 @@ public Object getValue(final ConstantPoolGen cpg) { final int nameIndex = ((org.apache.bcel.classfile.ConstantClass) c).getNameIndex(); c = cpg.getConstantPool().getConstant(nameIndex); return Type.getType(Type.internalTypeNameToSignature(((org.apache.bcel.classfile.ConstantUtf8) c).getBytes())); + case org.apache.bcel.Const.CONSTANT_Dynamic: + // Really not sure what to return here, maybe a BootstrapMethod instance but how do we get it? + return c; default: // Never reached throw new IllegalArgumentException("Unknown or invalid constant type at " + super.getIndex()); } diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java b/src/main/java/org/apache/bcel/generic/MethodGen.java index 3cf8f7339a..1cccda44a9 100644 --- a/src/main/java/org/apache/bcel/generic/MethodGen.java +++ b/src/main/java/org/apache/bcel/generic/MethodGen.java @@ -99,19 +99,16 @@ static final class BranchTarget { } } - private static BCELComparator bcelComparator = new BCELComparator() { + private static BCELComparator bcelComparator = new BCELComparator() { @Override - public boolean equals(final Object o1, final Object o2) { - final FieldGenOrMethodGen THIS = (FieldGenOrMethodGen) o1; - final FieldGenOrMethodGen THAT = (FieldGenOrMethodGen) o2; - return Objects.equals(THIS.getName(), THAT.getName()) && Objects.equals(THIS.getSignature(), THAT.getSignature()); + public boolean equals(final FieldGenOrMethodGen a, final FieldGenOrMethodGen b) { + return a == b || a != null && b != null && Objects.equals(a.getName(), b.getName()) && Objects.equals(a.getSignature(), b.getSignature()); } @Override - public int hashCode(final Object o) { - final FieldGenOrMethodGen THIS = (FieldGenOrMethodGen) o; - return THIS.getSignature().hashCode() ^ THIS.getName().hashCode(); + public int hashCode(final FieldGenOrMethodGen o) { + return o != null ? Objects.hash(o.getSignature(), o.getName()) : 0; } }; @@ -124,9 +121,9 @@ private static byte[] getByteCodes(final Method method) { } /** - * @return Comparison strategy object + * @return Comparison strategy object. */ - public static BCELComparator getComparator() { + public static BCELComparator getComparator() { return bcelComparator; } @@ -203,9 +200,9 @@ public static int getMaxStack(final ConstantPoolGen cp, final InstructionList il } /** - * @param comparator Comparison strategy object + * @param comparator Comparison strategy object. */ - public static void setComparator(final BCELComparator comparator) { + public static void setComparator(final BCELComparator comparator) { bcelComparator = comparator; } @@ -633,7 +630,7 @@ private void ensureExistingParameterAnnotationsUnpacked() { */ @Override public boolean equals(final Object obj) { - return bcelComparator.equals(this, obj); + return obj instanceof FieldGenOrMethodGen && bcelComparator.equals(this, (FieldGenOrMethodGen) obj); } // J5TODO: Should paramAnnotations be an array of arrays? Rather than an array of lists, this diff --git a/src/main/java/org/apache/bcel/generic/ObjectType.java b/src/main/java/org/apache/bcel/generic/ObjectType.java index 28e2125477..95a4df3f4c 100644 --- a/src/main/java/org/apache/bcel/generic/ObjectType.java +++ b/src/main/java/org/apache/bcel/generic/ObjectType.java @@ -22,7 +22,7 @@ import org.apache.bcel.classfile.Utility; /** - * Denotes reference such as java.lang.String. + * Denotes reference such as {@link String}. */ public class ObjectType extends ReferenceType { @@ -42,7 +42,7 @@ public static ObjectType getInstance(final String className) { /** * Constructs a new instance. * - * @param className fully qualified class name, e.g. java.lang.String + * @param className fully qualified class name, e.g. {@link String} */ public ObjectType(final String className) { super(Const.T_REFERENCE, "L" + Utility.packageToPath(className) + ";"); diff --git a/src/main/java/org/apache/bcel/generic/ReferenceType.java b/src/main/java/org/apache/bcel/generic/ReferenceType.java index 71f0d43423..546bf0ae19 100644 --- a/src/main/java/org/apache/bcel/generic/ReferenceType.java +++ b/src/main/java/org/apache/bcel/generic/ReferenceType.java @@ -56,8 +56,8 @@ public ReferenceType firstCommonSuperclass(final ReferenceType t) throws ClassNo return this; /* * TODO: Above sounds a little arbitrary. On the other hand, there is no object referenced by Type.NULL so we can also - * say all the objects referenced by Type.NULL were derived from java.lang.Object. However, the Java Language's - * "instanceof" operator proves us wrong: "null" is not referring to an instance of java.lang.Object :) + * say all the objects referenced by Type.NULL were derived from {@link Object}. However, the Java Language's + * "instanceof" operator proves us wrong: "null" is not referring to an instance of {@link Object} :) */ } if (this instanceof ArrayType || t instanceof ArrayType) { @@ -87,8 +87,8 @@ public ReferenceType getFirstCommonSuperclass(final ReferenceType t) throws Clas return this; /* * TODO: Above sounds a little arbitrary. On the other hand, there is no object referenced by Type.NULL so we can also - * say all the objects referenced by Type.NULL were derived from java.lang.Object. However, the Java Language's - * "instanceof" operator proves us wrong: "null" is not referring to an instance of java.lang.Object :) + * say all the objects referenced by Type.NULL were derived from {@link Object}. However, the Java Language's + * "instanceof" operator proves us wrong: "null" is not referring to an instance of {@link Object} :) */ } /* This code is from a bug report by Konstantin Shagin */ diff --git a/src/main/java/org/apache/bcel/generic/Type.java b/src/main/java/org/apache/bcel/generic/Type.java index 71b28383de..76b833907f 100644 --- a/src/main/java/org/apache/bcel/generic/Type.java +++ b/src/main/java/org/apache/bcel/generic/Type.java @@ -173,7 +173,7 @@ public static String getSignature(final java.lang.reflect.Method meth) { } /** - * Convert runtime java.lang.Class to BCEL Type object. + * Convert runtime {@link Class} to BCEL Type object. * * @param cls Java class * @return corresponding Type object @@ -252,7 +252,7 @@ public static Type getType(final String signature) throws StringIndexOutOfBounds } /** - * Convert runtime java.lang.Class[] to BCEL Type objects. + * Convert runtime {@code java.lang.Class[]} to BCEL Type objects. * * @param classes an array of runtime class objects * @return array of corresponding Type objects diff --git a/src/main/java/org/apache/bcel/util/BCELComparator.java b/src/main/java/org/apache/bcel/util/BCELComparator.java index 4e0d8a4a44..98e5d50f3b 100644 --- a/src/main/java/org/apache/bcel/util/BCELComparator.java +++ b/src/main/java/org/apache/bcel/util/BCELComparator.java @@ -17,26 +17,27 @@ package org.apache.bcel.util; /** - * Used for BCEL comparison strategy + * Used for BCEL comparison strategy. * + * @param What type we are comparing. * @since 5.2 */ -public interface BCELComparator { +public interface BCELComparator { /** - * Compare two objects and return what THIS.equals(THAT) should return + * Compares two objects and return what a.equals(b) should return. * - * @param THIS - * @param THAT - * @return true if and only if THIS equals THAT + * @param a an object. + * @param b an object to be compared with {@code a} for equality. + * @return {@code true} if the arguments are equal to each other and {@code false} otherwise. */ - boolean equals(Object THIS, Object THAT); + boolean equals(T a, T b); /** - * Return hash code for THIS.hashCode() + * Gets the hash code for o.hashCode() * - * @param THIS - * @return hash code for THIS.hashCode() + * @param o + * @return hash code for o.hashCode() */ - int hashCode(Object THIS); + int hashCode(T o); } diff --git a/src/main/java/org/apache/bcel/util/InstructionFinder.java b/src/main/java/org/apache/bcel/util/InstructionFinder.java index 07750cf5d6..62169817ee 100644 --- a/src/main/java/org/apache/bcel/util/InstructionFinder.java +++ b/src/main/java/org/apache/bcel/util/InstructionFinder.java @@ -369,7 +369,7 @@ public final Iterator search(final String pattern, final In // } // private static final String pattern2string( String pattern, boolean make_string ) { -// StringBuffer buf = new StringBuffer(); +// StringBuilder buf = new StringBuilder(); // for (int i = 0; i < pattern.length(); i++) { // char ch = pattern.charAt(i); // if (ch >= OFFSET) { diff --git a/src/main/java/org/apache/bcel/verifier/GraphicalVerifier.java b/src/main/java/org/apache/bcel/verifier/GraphicalVerifier.java index 115055e0b4..331eb5f979 100644 --- a/src/main/java/org/apache/bcel/verifier/GraphicalVerifier.java +++ b/src/main/java/org/apache/bcel/verifier/GraphicalVerifier.java @@ -40,7 +40,7 @@ public static void main(final String[] args) { new GraphicalVerifier(); } - /** Constructor. */ + /** Constructs a new instance. */ public GraphicalVerifier() { final VerifierAppFrame frame = new VerifierAppFrame(); // Frames �berpr�fen, die voreingestellte Gr��e haben diff --git a/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java b/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java index 8ec40e1239..e8482cc2ab 100644 --- a/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java +++ b/src/main/java/org/apache/bcel/verifier/VerifierAppFrame.java @@ -90,7 +90,7 @@ public class VerifierAppFrame extends JFrame { private final JMenuItem whatisMenuItem = new JMenuItem(); private final JMenuItem aboutMenuItem = new JMenuItem(); - /** Constructor. */ + /** Constructs a new instance. */ public VerifierAppFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { diff --git a/src/main/java/org/apache/bcel/verifier/VerifyDialog.java b/src/main/java/org/apache/bcel/verifier/VerifyDialog.java index 9d316b02ca..88ef3b3ffd 100644 --- a/src/main/java/org/apache/bcel/verifier/VerifyDialog.java +++ b/src/main/java/org/apache/bcel/verifier/VerifyDialog.java @@ -178,9 +178,9 @@ public VerifyDialog(final Frame owner, final String title, final boolean modal) } /** - * Use this constructor if you want a possibility to verify other class files than java.lang.Object. + * Use this constructor if you want a possibility to verify other class files than {@link Object}. * - * @param fullyQualifiedClassName java.lang.String + * @param fullyQualifiedClassName "java.lang.String" */ public VerifyDialog(String fullyQualifiedClassName) { final int dotclasspos = fullyQualifiedClassName.lastIndexOf(JavaClass.EXTENSION); diff --git a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java index 810630eb74..34f9f5f35f 100644 --- a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java +++ b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java @@ -1321,7 +1321,7 @@ public VerificationResult do_verify() { /** * Ensures that every class has a super class and that final classes are not subclassed. This means, the class - * this Pass2Verifier operates on has proper super classes (transitively) up to java.lang.Object. The reason for really + * this Pass2Verifier operates on has proper super classes (transitively) up to {@link Object}. The reason for really * loading (and Pass1-verifying) all of those classes here is that we need them in Pass2 anyway to verify no final * methods are overridden (that could be declared anywhere in the ancestor hierarchy). * diff --git a/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java b/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java index 3764ebae74..25def60f6e 100644 --- a/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java +++ b/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java @@ -28,6 +28,7 @@ import org.apache.bcel.classfile.ConstantCP; import org.apache.bcel.classfile.ConstantClass; import org.apache.bcel.classfile.ConstantDouble; +import org.apache.bcel.classfile.ConstantDynamic; import org.apache.bcel.classfile.ConstantFieldref; import org.apache.bcel.classfile.ConstantFloat; import org.apache.bcel.classfile.ConstantInteger; @@ -651,9 +652,10 @@ public void visitLDC(final LDC ldc) { final Constant c = constantPoolGen.getConstant(ldc.getIndex()); if (c instanceof ConstantClass) { addMessage("Operand of LDC or LDC_W is CONSTANT_Class '" + tostring(c) + "' - this is only supported in JDK 1.5 and higher."); - } else if (!(c instanceof ConstantInteger || c instanceof ConstantFloat || c instanceof ConstantString)) { + } else if (!(c instanceof ConstantInteger || c instanceof ConstantFloat || c instanceof ConstantString || c instanceof ConstantDynamic)) { constraintViolated(ldc, - "Operand of LDC or LDC_W must be one of CONSTANT_Integer, CONSTANT_Float or CONSTANT_String, but is '" + tostring(c) + "'."); + "Operand of LDC or LDC_W must be one of CONSTANT_Integer, CONSTANT_Float, CONSTANT_String or CONSTANT_Dynamic but is '" + + tostring(c) + "'."); } } diff --git a/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java b/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java index b33e43bbd9..d501d097c3 100644 --- a/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java +++ b/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandler.java @@ -20,7 +20,7 @@ import org.apache.bcel.generic.ObjectType; /** - * This class represents an exception handler; that is, an ObjectType representing a subclass of java.lang.Throwable and + * This class represents an exception handler; that is, an ObjectType representing a subclass of {@link Throwable} and * the instruction the handler starts off (represented by an InstructionContext). */ public class ExceptionHandler { diff --git a/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java b/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java index be1cdb1270..0a9dbab8c8 100644 --- a/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java +++ b/src/main/java/org/apache/bcel/verifier/structurals/ExceptionHandlers.java @@ -41,7 +41,7 @@ public class ExceptionHandlers { private final Map> exceptionHandlers; /** - * Constructor. Creates a new ExceptionHandlers instance. + * Constructs a new ExceptionHandlers instance. */ public ExceptionHandlers(final MethodGen mg) { exceptionHandlers = new HashMap<>(); diff --git a/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java b/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java index baa03b99ca..d06665588c 100644 --- a/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java +++ b/src/main/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java @@ -20,6 +20,7 @@ import org.apache.bcel.classfile.Constant; import org.apache.bcel.classfile.ConstantClass; import org.apache.bcel.classfile.ConstantDouble; +import org.apache.bcel.classfile.ConstantDynamic; import org.apache.bcel.classfile.ConstantFloat; import org.apache.bcel.classfile.ConstantInteger; import org.apache.bcel.classfile.ConstantLong; @@ -70,7 +71,7 @@ public class ExecutionVisitor extends EmptyVisitor { private ConstantPoolGen cpg; /** - * Constructor. Constructs a new instance of this class. + * Constructs a new instance of this class. */ public ExecutionVisitor() { } @@ -1054,6 +1055,9 @@ public void visitLDC(final LDC o) { if (c instanceof ConstantClass) { stack().push(Type.CLASS); } + if (c instanceof ConstantDynamic) { + stack().push(Type.OBJECT); + } } /** Symbolically executes the corresponding Java Virtual Machine instruction. */ diff --git a/src/main/java/org/apache/bcel/verifier/structurals/GenericArray.java b/src/main/java/org/apache/bcel/verifier/structurals/GenericArray.java index 4cd699ac7d..0fa6e412f0 100644 --- a/src/main/java/org/apache/bcel/verifier/structurals/GenericArray.java +++ b/src/main/java/org/apache/bcel/verifier/structurals/GenericArray.java @@ -20,7 +20,7 @@ /** * A placeholder class that can be used to create an ObjectType of which has some of the properties arrays have. They - * implement java.lang.Cloneable and java.io.Serializable and they extend java.lang.Object. + * implement {@link Cloneable} and {@link java.io.Serializable} and they extend {@link Object}. */ public class GenericArray implements Cloneable, Serializable { diff --git a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java index e41051b862..0b637e6dc8 100644 --- a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java +++ b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java @@ -21,6 +21,7 @@ import org.apache.bcel.classfile.Constant; import org.apache.bcel.classfile.ConstantClass; import org.apache.bcel.classfile.ConstantDouble; +import org.apache.bcel.classfile.ConstantDynamic; import org.apache.bcel.classfile.ConstantFieldref; import org.apache.bcel.classfile.ConstantFloat; import org.apache.bcel.classfile.ConstantInteger; @@ -2030,9 +2031,14 @@ public void visitLDC(final LDC o) { // visitCPInstruction is called first. final Constant c = cpg.getConstant(o.getIndex()); - if (!(c instanceof ConstantInteger || c instanceof ConstantFloat || c instanceof ConstantString || c instanceof ConstantClass)) { + if (!(c instanceof ConstantInteger + || c instanceof ConstantFloat + || c instanceof ConstantString + || c instanceof ConstantClass + || c instanceof ConstantDynamic)) { constraintViolated(o, - "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float, a CONSTANT_String or a CONSTANT_Class, but is '" + c + "'."); + "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float, a CONSTANT_String, a CONSTANT_Class, or a CONSTANT_Dynamic but is '" + + c + "'."); } } diff --git a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java index 49300a0318..565c95362e 100644 --- a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java +++ b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java @@ -398,7 +398,7 @@ private static InstructionHandle[] getSuccessors(final InstructionHandle instruc // CHECKSTYLE:ON /** - * Constructor. + * Constructs a new instance. * * @param mg A MethodGen object representing method to create the Subroutine objects of. Assumes that JustIce strict * checks are needed. @@ -408,7 +408,7 @@ public Subroutines(final MethodGen mg) { } /** - * Constructor. + * Constructs a new instance. * * @param mg A MethodGen object representing method to create the Subroutine objects of. * @param enableJustIceCheck whether to enable additional JustIce checks diff --git a/src/site/xdoc/download_bcel.xml b/src/site/xdoc/download_bcel.xml index b07a8d3e77..4d6c7b02a2 100644 --- a/src/site/xdoc/download_bcel.xml +++ b/src/site/xdoc/download_bcel.xml @@ -113,32 +113,32 @@ limitations under the License.

-
+
- - - + + + - - - + + +
bcel-6.8.0-bin.tar.gzsha512pgpbcel-6.8.1-bin.tar.gzsha512pgp
bcel-6.8.0-bin.zipsha512pgpbcel-6.8.1-bin.zipsha512pgp
- - - + + + - - - + + +
bcel-6.8.0-src.tar.gzsha512pgpbcel-6.8.1-src.tar.gzsha512pgp
bcel-6.8.0-src.zipsha512pgpbcel-6.8.1-src.zipsha512pgp
diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml index b8a58a8958..da5692d481 100644 --- a/src/site/xdoc/index.xml +++ b/src/site/xdoc/index.xml @@ -24,7 +24,6 @@ Commons Documentation Team -

The Byte Code Engineering Library (Apache Commons BCEL™) is intended to give users a @@ -34,7 +33,6 @@ of the given class: methods, fields and byte code instructions, in particular.

-

Such objects can be read from an existing file, be transformed by a program (e.g. a class loader at run-time) and written to a file again. @@ -43,13 +41,11 @@ if you want to learn about the Java Virtual Machine (JVM) and the format of Java .class files.

-

BCEL contains a byte code verifier named JustIce, which usually gives you much better information about what's wrong with your code than the standard JVM message.

-

BCEL is already being used successfully in several projects such as compilers, optimizers, obsfuscators, code generators @@ -58,7 +54,6 @@ might want to have a look into the ASM project at objectweb.

-

The package descriptions in the Javadoc give an overview of the available features @@ -69,7 +64,6 @@ browsed, or you can browse/contribute via GitHub.

-

The latest stable release of BCEL is here, you may:

    @@ -82,7 +76,6 @@

-

The commons developer mailing list is the main channel of communication for contributors. Please remember that the lists are shared between all commons components, so prefix your email by [bcel].

diff --git a/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java b/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java index 18e1f23949..b94a4a4c0a 100644 --- a/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java +++ b/src/test/java/org/apache/bcel/EnclosingMethodAttributeTestCase.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.Test; public class EnclosingMethodAttributeTestCase extends AbstractTestCase { + /** * Check that we can save and load the attribute correctly. */ diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java index b482efe0de..e7f08c96eb 100644 --- a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java +++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java @@ -385,7 +385,17 @@ public void visitModuleRequires(final ModuleRequires constantModule) { append(constantModule); append(constantModule.toString(pool)); final String s = constantModule.toString(pool).trim(); - assertTrue(StringUtils.startsWithAny(s, "jdk.", "java.", "org.junit", "org.apiguardian.api", "org.opentest4j"), s); + final boolean condition = StringUtils.startsWithAny(s, + "jdk.", + "java.", + "org.junit", + "org.apiguardian.api", + "org.opentest4j", + "net.bytebuddy", + "com.sun.jna", + "junit", + "org.hamcrest"); + assertTrue(condition, s); } @Override diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java index 3c154facb1..3454a1a8ee 100644 --- a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java +++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java @@ -66,7 +66,7 @@ public void testClassWithDoubleConstantPoolItem() throws ClassNotFoundException, // Next constant pool entry will be invalid so skip it i++; } - } catch (Throwable t) { + } catch (final Throwable t) { t.printStackTrace(); fail(); } @@ -92,7 +92,7 @@ public void testClassWithLongConstantPoolItem() throws ClassNotFoundException, I // Next constant pool entry will be invalid so skip it i++; } - } catch (Throwable t) { + } catch (final Throwable t) { t.printStackTrace(); fail(); } diff --git a/src/test/java/org/apache/bcel/classfile/ConstantTest.java b/src/test/java/org/apache/bcel/classfile/ConstantTest.java new file mode 100644 index 0000000000..3769b58bbd --- /dev/null +++ b/src/test/java/org/apache/bcel/classfile/ConstantTest.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.bcel.classfile; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +/** + * Tests {@link Constant}. + */ +public class ConstantTest { + + @Test + public void testBCELComparator() throws Exception { + final Constant obj = new ConstantClass(1); + assertTrue(Constant.getComparator().equals(null, null)); + assertTrue(Constant.getComparator().equals(obj, obj)); + assertFalse(Constant.getComparator().equals(obj, null)); + assertFalse(Constant.getComparator().equals(null, obj)); + } +} diff --git a/src/test/java/org/apache/bcel/classfile/FieldTest.java b/src/test/java/org/apache/bcel/classfile/FieldTest.java new file mode 100644 index 0000000000..3b41293f2b --- /dev/null +++ b/src/test/java/org/apache/bcel/classfile/FieldTest.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.bcel.classfile; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +/** + * Tests {@link Field}. + */ +public class FieldTest { + + @Test + public void testBCELComparator() throws Exception { + final Field obj = new Field(1, 1, 1, null, null); + assertTrue(Field.getComparator().equals(null, null)); + assertTrue(Field.getComparator().equals(obj, obj)); + assertFalse(Field.getComparator().equals(obj, null)); + assertFalse(Field.getComparator().equals(null, obj)); + } +} diff --git a/src/test/java/org/apache/bcel/classfile/TestJira368.java b/src/test/java/org/apache/bcel/classfile/TestJira368.java index 83cc510eb0..427276b913 100644 --- a/src/test/java/org/apache/bcel/classfile/TestJira368.java +++ b/src/test/java/org/apache/bcel/classfile/TestJira368.java @@ -35,7 +35,7 @@ private JavaClass parseJavaClass() throws IOException { @Test public void testInstructionListStringBrief() throws Exception { - for (Method method : parseJavaClass().getMethods()) { + for (final Method method : parseJavaClass().getMethods()) { if (!method.isAbstract() && !method.isNative()) { final InstructionList instructionList = new InstructionList(method.getCode().getCode()); final String string = instructionList.toString(false); @@ -46,7 +46,7 @@ public void testInstructionListStringBrief() throws Exception { @Test public void testInstructionListStringVerbose() throws Exception { - for (Method method : parseJavaClass().getMethods()) { + for (final Method method : parseJavaClass().getMethods()) { if (!method.isAbstract() && !method.isNative()) { final InstructionList instructionList = new InstructionList(method.getCode().getCode()); final String string = instructionList.toString(true); diff --git a/src/test/java/org/apache/bcel/generic/ClassGenTest.java b/src/test/java/org/apache/bcel/generic/ClassGenTest.java new file mode 100644 index 0000000000..742805b29e --- /dev/null +++ b/src/test/java/org/apache/bcel/generic/ClassGenTest.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.bcel.generic; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +/** + * Tests {@link ClassGen}. + */ +public class ClassGenTest { + + @Test + public void testBCELComparator() throws Exception { + final ClassGen obj = new ClassGen("", "", "", 0, null); + assertTrue(ClassGen.getComparator().equals(null, null)); + assertTrue(ClassGen.getComparator().equals(obj, obj)); + assertFalse(ClassGen.getComparator().equals(obj, null)); + assertFalse(ClassGen.getComparator().equals(null, obj)); + } +} diff --git a/src/test/java/org/apache/bcel/generic/FieldGenTest.java b/src/test/java/org/apache/bcel/generic/FieldGenTest.java new file mode 100644 index 0000000000..cbf366bbda --- /dev/null +++ b/src/test/java/org/apache/bcel/generic/FieldGenTest.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.bcel.generic; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.apache.bcel.classfile.ConstantLong; +import org.apache.bcel.classfile.ConstantPool; +import org.apache.bcel.classfile.Field; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * Tests {@link FieldGen}. + */ +public class FieldGenTest { + + @Test + @Disabled + public void testBCELComparator() throws Exception { + final ConstantLong[] constantPool = { new ConstantLong(0), new ConstantLong(0) }; + final FieldGen obj = new FieldGen(new Field(0, 0, 0, null, new ConstantPool(constantPool)), new ConstantPoolGen(constantPool)); + assertTrue(FieldGen.getComparator().equals(null, null)); + assertTrue(FieldGen.getComparator().equals(obj, obj)); + assertFalse(FieldGen.getComparator().equals(obj, null)); + assertFalse(FieldGen.getComparator().equals(null, obj)); + } +} diff --git a/src/test/java/org/apache/bcel/generic/JavaHome.java b/src/test/java/org/apache/bcel/generic/JavaHome.java index e4d04d45ba..f23be5537a 100644 --- a/src/test/java/org/apache/bcel/generic/JavaHome.java +++ b/src/test/java/org/apache/bcel/generic/JavaHome.java @@ -68,7 +68,7 @@ public class JavaHome { private static Stream find(final Path start, final int maxDepth, final BiPredicate matcher, final FileVisitOption... options) { - // TODO Apache Commons 2.14.0: Use FilesUncheck + // TODO Apache Commons 2.14.0: Use FilesUncheck return Files.exists(start) ? Uncheck.apply(Files::find, start, maxDepth, matcher, options) : Stream.empty(); } diff --git a/src/test/java/org/apache/bcel/generic/TypeTestCase.java b/src/test/java/org/apache/bcel/generic/TypeTestCase.java index 4fd5c1166c..303a75ba4c 100644 --- a/src/test/java/org/apache/bcel/generic/TypeTestCase.java +++ b/src/test/java/org/apache/bcel/generic/TypeTestCase.java @@ -78,7 +78,8 @@ public void testInternalTypeNametoSignature() { "org/apache/bcel/classfile/Method", "org/apache/bcel/classfile/Synthetic", "org/apache/bcel/generic/ConstantPoolGen", - "org/apache/bcel/generic/MethodGen"}) + "org/apache/bcel/generic/MethodGen", + "com/foo/Foo"}) // @formatter:on public void testLDC(final String className) throws Exception { final JavaClass jc = Repository.lookupClass(className); @@ -90,7 +91,7 @@ public void testLDC(final String className) throws Exception { for (final InstructionHandle instructionHandle : instructionList) { instructionHandle.accept(new EmptyVisitor() { @Override - public void visitLDC(LDC obj) { + public void visitLDC(final LDC obj) { assertNotNull(obj.getValue(cpg)); } }); diff --git a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java index 1cdeff2d9d..8ab68d6c6d 100644 --- a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java +++ b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java @@ -174,7 +174,7 @@ public void testHelloWorld() throws Exception { /* * Dumps a class using "javap" and compare with the same class recreated using BCELifier, "javac", "java" and dumped with "javap". - * + * * TODO: detect if JDK present and skip test if not */ @ParameterizedTest diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java index bfd84f28ce..5a8502d173 100644 --- a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java +++ b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java @@ -109,7 +109,7 @@ public void testCompileAndVerify() throws ClassNotFoundException { at org.apache.bcel.verifier.structurals.Pass3bVerifier.do_verify(Pass3bVerifier.java:386) ... 74 more * }
- * + * * @throws ClassNotFoundException */ @Test diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java new file mode 100644 index 0000000000..a92a92240f --- /dev/null +++ b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.bcel.verifier; + +import java.io.File; +import java.io.FileInputStream; + +import org.apache.bcel.AbstractTestCase; +import org.apache.bcel.classfile.ClassParser; +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; +import org.apache.bcel.generic.ConstantPoolGen; +import org.apache.bcel.generic.EmptyVisitor; +import org.apache.bcel.generic.Instruction; +import org.apache.bcel.generic.LDC; +import org.apache.bcel.generic.MethodGen; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests BCEL-370. + */ +public class JiraBcel370TestCase extends AbstractTestCase { + @ParameterizedTest + @ValueSource(strings = { + // @formatter:off + "target/test-classes/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser$ClassBlockContext.class", + "target/test-classes/com/foo/Foo.class" + }) + // @formatter:on + public void testLdcGetType(final String classFileName) throws Exception { + try (FileInputStream file = new FileInputStream(classFileName)) { + final ClassParser parser = new ClassParser(file, new File(classFileName).getName()); + final JavaClass clazz = parser.parse(); + + final Method[] methods = clazz.getMethods(); + + final ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool()); + final MethodGen methodGen = new MethodGen(methods[0], classFileName, cp); + + // The first instruction is an LDC CONSTANT_Dynamic added by Jacoco + final Instruction instruction = methodGen.getInstructionList().getInstructions()[0]; + + instruction.accept(new EmptyVisitor() { + @Override + public void visitLDC(final LDC ldc) { + // Without the change to LDC.getType() this fails because the tag is CONSTANT_Dynamic + ldc.getType(cp); + } + }); + } + } + + @ParameterizedTest + @ValueSource(strings = { + // @formatter:off + "com.foo.Foo" + }) + // @formatter:on + public void testVerify(final String className) throws ClassNotFoundException { + // Without the changes to the verifier this fails because it doesn't allow LDC CONSTANT_Dynamic + Verifier.verifyType(className); + } +} diff --git a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java new file mode 100644 index 0000000000..c368c392c4 --- /dev/null +++ b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bcel.verifier.statics; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.util.stream.Stream; + +import org.apache.bcel.Const; +import org.apache.bcel.Repository; +import org.apache.bcel.classfile.Attribute; +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.CodeException; +import org.apache.bcel.classfile.Constant; +import org.apache.bcel.classfile.ConstantDouble; +import org.apache.bcel.classfile.ConstantFieldref; +import org.apache.bcel.classfile.ConstantInterfaceMethodref; +import org.apache.bcel.classfile.ConstantInvokeDynamic; +import org.apache.bcel.classfile.ConstantLong; +import org.apache.bcel.classfile.ConstantMethodHandle; +import org.apache.bcel.classfile.ConstantMethodType; +import org.apache.bcel.classfile.ConstantModule; +import org.apache.bcel.classfile.ConstantNameAndType; +import org.apache.bcel.classfile.ConstantPackage; +import org.apache.bcel.classfile.ConstantPool; +import org.apache.bcel.classfile.ConstantUtf8; +import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; +import org.apache.bcel.util.SyntheticRepository; +import org.apache.bcel.verifier.VerificationResult; +import org.apache.bcel.verifier.Verifier; +import org.apache.bcel.verifier.VerifierFactory; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +class Pass3aVerifierTestCase { + public static Stream constantsNotSupportedByLdc() { + return Stream.of( + new ConstantFieldref(0, 0), + new ConstantInterfaceMethodref(0, 0), + new ConstantInvokeDynamic(0, 0), + new ConstantMethodHandle(0, 0), + new ConstantDouble(0D), + new ConstantLong(0L), + new ConstantMethodHandle(0, 0), + new ConstantMethodType(0), + new ConstantModule(0), + new ConstantNameAndType(0, 0), + new ConstantPackage(0), + new ConstantUtf8("constant") + ); + } + @AfterAll + public static void restoreRepository() { + // We have set our mock repository, revert the change + Repository.setRepository(SyntheticRepository.getInstance()); + } + private Verifier verifier; + private org.apache.bcel.util.Repository repository; + + private ConstantPool cp; + + private JavaClass javaClass; + + @ParameterizedTest + @MethodSource("constantsNotSupportedByLdc") + public void rejectLdcConstant(final Constant constant) { + // LDC the constant 0 and then return + final byte[] methodCode = { + Const.LDC, + 0, + 0, + (byte) Const.RETURN, + }; + + final Code code = new Code(0, 0, 0, 0, methodCode, new CodeException[0], new Attribute[0], cp); + + when(cp.getConstantPool()).thenReturn(new Constant[] {constant}); + + final Attribute[] attributes = {code}; + final Method method = new Method(0, 0, 0, attributes, cp); + + when(javaClass.getMethods()).thenReturn(new Method[] {method}); + + final Pass3aVerifier pass3aVerifier = new Pass3aVerifier(verifier, 0); + final VerificationResult verificationResult = pass3aVerifier.do_verify(); + + assertThat(verificationResult.getStatus()).isEqualTo(VerificationResult.VERIFIED_REJECTED); + assertThat(verificationResult.getMessage()).startsWith("Instruction ldc[18](2) 0 constraint violated: Operand of LDC"); + } + + @BeforeEach + void setup() throws ClassNotFoundException { + final String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo"; + + verifier = spy(VerifierFactory.getVerifier(className)); + repository = mock(org.apache.bcel.util.Repository.class); + cp = mock(ConstantPool.class); + javaClass = mock(JavaClass.class); + + // Mock the verifier + doReturn(VerificationResult.VR_OK).when(verifier).doPass2(); + + // Mock the repository + Repository.setRepository(repository); + when(repository.loadClass(className)).thenReturn(javaClass); + + // Mock the constant pool + when(cp.getConstantPool()).thenReturn(new Constant[] {new ConstantModule(0)}); + + // Mock the java class + when(javaClass.getConstantPool()).thenReturn(cp); + } +} + diff --git a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java new file mode 100644 index 0000000000..72d4c04b6e --- /dev/null +++ b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bcel.verifier.structurals; + +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.bcel.classfile.Constant; +import org.apache.bcel.generic.ConstantPoolGen; +import org.apache.bcel.generic.LDC; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class InstConstraintVisitorTestCase { + private ConstantPoolGen cp; + + @ParameterizedTest + @MethodSource("org.apache.bcel.verifier.statics.Pass3aVerifierTestCase#constantsNotSupportedByLdc") + public void rejectLdcConstantModule(final Constant constant) { + final InstConstraintVisitor visitor = new InstConstraintVisitor(); + + cp = mock(ConstantPoolGen.class); + when(cp.getConstant(0)).thenReturn(constant); + + visitor.setConstantPoolGen(cp); + + final LDC ldc = new LDC(0); + + assertThatCode(() -> visitor.visitLDC(ldc)).hasMessageStartingWith("Instruction LDC constraint violated: Referenced constant should be a"); + } + + @BeforeEach + public void setup() { + cp = mock(ConstantPoolGen.class); + } +} diff --git a/src/test/resources/com/foo/Foo.class b/src/test/resources/com/foo/Foo.class new file mode 100644 index 0000000000000000000000000000000000000000..f405e5fe2098b6c4f70e417eb7197d98fa8858d9 GIT binary patch literal 770 zcmYjO-EI;=7(D|E3tL(!BCS?!)v7?zy{I=0YN9ob7+Oe*T(lQvfPpSucA91ByZ8=X zXrj@WXuS3Xd>iB0g`{LN-`{?7zVn^=^Y6zm0MGH*LJV;eMg|Ea1#%;KDQ#DJL%Z1> zsa_zEeCBvg@IoM7DtFRIA#K9SUmWQ~LlRdA;JE$Pd#3Y5i9?72W={mU!9F-bZi#gtJ`Xu9|E&v_79+)E3%~ z1K;t6iPA0YT=}89bxM5L>o7p5bu7VF9V42kwW-Z2X`a*u| zH|`x)zClzrzQU}=jrM2OW6093uqVmSg2_CE9Bai0w}4gTnGqqv7r4eaLAmGzi`Qwx zL3=Qw3)yH;qw)pjj$yPv^4Dxel8s4T3$Zhd!ATKz&I(^*4pSsd$k!_1e*Qt?J9a)X Q3o(k3T|<>V#JUCi2Ui=Jr2qf` literal 0 HcmV?d00001 diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser$ClassBlockContext.class b/src/test/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser$ClassBlockContext.class new file mode 100644 index 0000000000000000000000000000000000000000..c5da924abfebdf3de76ed1fa0dbc5d639a84429f GIT binary patch literal 2624 zcmcImTUQ%Z6#h;UG9d|trbv<2OBFR2=va!SHj#UgUroM3tM z#s8pd`5*M9ULIWd>Z?D+XI<_|rZ@_8Ef)BY*=P2d^X+f%voHDWub+PbFojPI+@q^HF*O|NCo6KcWbt(Isp ztY>o-TQLh|i z;o5Xsj+UyJt8|jZr9?5;w)cdsDR#y|cb8%8JXj1v|4y94=8NQ+I0sItU|Gd!qS05= z+}>a1%^(ANYfjzcx~(WhS4-A|lhmir<9lEyN7fjUHQ83SSaSUQzkafIZu?8bV0x%P0}c$WZvAwpEko)hb)h%ft~jpyQZ|%59XiGG8QrDZJVU1`T@r+6$$jBbiDb)Xojk2C zMYDcSNZ7J@xTIu*+Ha@W{)q@f{jz#eXr7#2==rnT>3=%~m1CFauH)_~-|_n|D>gq| zolbmegGr6!#%w4!nIWO8b9V(Q)v)vJ8a5aP=B3mvt$4HRcni14ffR89dO&{$&`-|+dYeHUQIfA@mXENqn$NK4 zb3~57#-cInJKBiAcO_1r$CG`?&^k?PI)H2R1FeT}Jpd~OV3`1HV3xpQW3iJ+{UM~x zG14$b0;FZ486)(;4pKG$1A6j>=ZKH@#H{a0A7(Ys!5ShReIH=?s~fmUXbi96b=vct z{W3t!c2Ntz!uT4Q!V!%8Pe?>C9w(*+TKCf0=(3LCZ93Tt_9wv^Sm}f#Nr3U>HQY=N zhKy&Ajc4%&-Xznv=x8@wzUD2`jFKjTcLtJvR?)jpYlvL+?|{HQ$*d-RM9mL8NPC5z kBeX|TAALk3Npg^6isY*#-=+Ns-h)NbzoJEw*^VyyH%Eo?wEzGB literal 0 HcmV?d00001 diff --git a/src/test/resources/ossfuzz/issue51980/Test.class b/src/test/resources/ossfuzz/issue51980/Test.class deleted file mode 100644 index 314e094540a08082c79c24861e7cb65f21e91a51..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 tcmX^0Z`Z!PzgZX=K*%{iC6$$d;W!W&F+^({-DikqfPe%BMg|6i6aew$57qzx diff --git a/src/test/resources/ossfuzz/issue51989/Test.class b/src/test/resources/ossfuzz/issue51989/Test.class deleted file mode 100644 index cce2039dbeede92a9b46a4dbc154aa9550813a44..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 88 zcmX^0Z`Zyo1_ovZW@aE}U}R7VD$Og&%uNl;EY3{INexIWO3Y0yNiA~B%gZlGEXmBz kD`o%z0}vqq)Wglp?99l(z{H>)V}0u1t}HeNRyH;^0AOeqA^-pY diff --git a/src/test/resources/ossfuzz/issue52168/Test.class b/src/test/resources/ossfuzz/issue52168/Test.class deleted file mode 100644 index e92207bcaa78eccd311f70c1c95f680a68c27ec9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 61 vcmX^0Z`ZyUW_1PzE-oPk1_o9}Ai*HS%_Srx#K9#H%LU{E5i3X(3Xs?U2R#Jk diff --git a/src/test/resources/ossfuzz/issue53543/Test.class b/src/test/resources/ossfuzz/issue53543/Test.class deleted file mode 100644 index 808e33798757a07da104c6b81d623e02f96b9aa6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 57 zcmX^0Z`VFvV+IBWW=00y;F84TY~RF!ki?{%R1OA42Ii8~qGF(2ZYr3;2o{5I0O9%% AhyVZp diff --git a/src/test/resources/ossfuzz/issue53544a/Test.class b/src/test/resources/ossfuzz/issue53544a/Test.class deleted file mode 100644 index 5fbdd67f7c4c88b7ca382b1273057314ca156c75..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 49 ucmX^0Z`VEs1~y>^Hbx-Dz;Fu8=jUf;6Jg`#VgLf5I2hzIFg7x1^8)}B6?Fci(*T?Kj_k`=9^)?Kgk$&CmY&Uw-xLU;e}QfAh{mXy+)jxmp!#{ue!+-qAZ}$H9+i(Bk z55D>455N1P@BGit{o_^tcAY=^$=?4qe%$}d|NZ%!|Ndn7vvoC<(hV(ZJKZSi^G2qWL(TYmeYLoF%{^k~UOCCghFSW_eJ)(O=egpmAWA}*s z7vq}C+`oyq3s<4nUzX+q+%37w-I7~;`8So@)ST-cQM(E~{k^H_@@{$m`;s@%-;3sc zI@AE}53*f_UO%wr0^BXR3oneGPNk+xw(gePg{#oJTj~~HOU`wVh|6#ldiRKQi?1c; zx<|xixC*^{M7qV-l5^c7;xb%?-aR7S;%mvd?h$bru0rn~k#6y|46KhM7>4_1j)61g@R-$i_jA8Sr_Z{#lW)A#X1=ibQkE_ac;$nyfv z-}grDBF_svf8QIqi##vz{C#iaF7mv<^Y^`xyU6nb&)@e(?jp|%Jb&LCxr;n6@ceym zv)QgFz(cGX!UD+_#o0j4pvH8%({axd5Y9)+A{nY5*IQs4E-hdQ)=&HtffVQrH_cfYBvTWrL|V zH5Xvi%9@1$n0ixl0YdJ<>-qc)x4f}DT z6!u09U~~yo*@{>vL;CrQ3KeZL|xf1*PEIPuwg$=l)~Pq0gNtzDjQ6_sks27 zR@NkGB5D8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