├── .asf.yaml ├── .gitattributes ├── .github ├── GH-ROBOTS.txt ├── dependabot.yml ├── pull_request_template.md └── workflows │ ├── codeql-analysis.yml │ ├── dependency-review.yml │ ├── maven.yml │ └── scorecards-analysis.yml ├── .gitignore ├── BUILDING.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── RELEASE-NOTES.txt ├── SECURITY.md ├── pom.xml └── src ├── changes ├── changes.xml └── release-notes.vm ├── conf ├── checkstyle-suppressions.xml └── checkstyle.xml ├── main ├── assembly │ ├── bin.xml │ └── src.xml ├── java │ └── org │ │ └── apache │ │ └── commons │ │ └── beanutils2 │ │ ├── BaseDynaBeanMapDecorator.java │ │ ├── BasicDynaBean.java │ │ ├── BasicDynaClass.java │ │ ├── BeanAccessLanguageException.java │ │ ├── BeanComparator.java │ │ ├── BeanIntrospectionData.java │ │ ├── BeanIntrospector.java │ │ ├── BeanMap.java │ │ ├── BeanPredicate.java │ │ ├── BeanPropertyValueChangeConsumer.java │ │ ├── BeanPropertyValueEqualsPredicate.java │ │ ├── BeanToPropertyValueTransformer.java │ │ ├── BeanUtils.java │ │ ├── BeanUtilsBean.java │ │ ├── ConstructorUtils.java │ │ ├── ContextClassLoaderLocal.java │ │ ├── ConversionException.java │ │ ├── ConvertUtils.java │ │ ├── ConvertUtilsBean.java │ │ ├── Converter.java │ │ ├── ConvertingWrapDynaBean.java │ │ ├── DefaultBeanIntrospector.java │ │ ├── DefaultIntrospectionContext.java │ │ ├── DynaBean.java │ │ ├── DynaBeanPropertyMapDecorator.java │ │ ├── DynaClass.java │ │ ├── DynaProperty.java │ │ ├── FluentPropertyBeanIntrospector.java │ │ ├── IntrospectionContext.java │ │ ├── LazyDynaBean.java │ │ ├── LazyDynaClass.java │ │ ├── LazyDynaList.java │ │ ├── LazyDynaMap.java │ │ ├── MappedPropertyDescriptor.java │ │ ├── MethodUtils.java │ │ ├── MutableDynaClass.java │ │ ├── NestedNullException.java │ │ ├── PropertyDescriptors.java │ │ ├── PropertyUtils.java │ │ ├── PropertyUtilsBean.java │ │ ├── SuppressPropertiesBeanIntrospector.java │ │ ├── TestEnum.java │ │ ├── WrapDynaBean.java │ │ ├── WrapDynaClass.java │ │ ├── converters │ │ ├── AbstractConverter.java │ │ ├── ArrayConverter.java │ │ ├── BigDecimalConverter.java │ │ ├── BigIntegerConverter.java │ │ ├── BooleanConverter.java │ │ ├── ByteConverter.java │ │ ├── CalendarConverter.java │ │ ├── CharacterConverter.java │ │ ├── ClassConverter.java │ │ ├── ColorConverter.java │ │ ├── ConverterFacade.java │ │ ├── DateConverter.java │ │ ├── DateTimeConverter.java │ │ ├── DimensionConverter.java │ │ ├── DoubleConverter.java │ │ ├── DurationConverter.java │ │ ├── EnumConverter.java │ │ ├── FileConverter.java │ │ ├── FloatConverter.java │ │ ├── InetAddressConverter.java │ │ ├── IntegerConverter.java │ │ ├── LocalDateConverter.java │ │ ├── LocalDateTimeConverter.java │ │ ├── LocalTimeConverter.java │ │ ├── LocaleConverter.java │ │ ├── LongConverter.java │ │ ├── MonthDayConverter.java │ │ ├── NumberConverter.java │ │ ├── OffsetDateTimeConverter.java │ │ ├── OffsetTimeConverter.java │ │ ├── PathConverter.java │ │ ├── PatternConverter.java │ │ ├── PeriodConverter.java │ │ ├── PointConverter.java │ │ ├── ShortConverter.java │ │ ├── StringConverter.java │ │ ├── URIConverter.java │ │ ├── URLConverter.java │ │ ├── UUIDConverter.java │ │ ├── YearConverter.java │ │ ├── YearMonthConverter.java │ │ ├── ZoneIdConverter.java │ │ ├── ZoneOffsetConverter.java │ │ ├── ZonedDateTimeConverter.java │ │ └── package-info.java │ │ ├── expression │ │ ├── DefaultResolver.java │ │ ├── Resolver.java │ │ └── package-info.java │ │ ├── locale │ │ ├── BaseLocaleConverter.java │ │ ├── LocaleBeanUtils.java │ │ ├── LocaleBeanUtilsBean.java │ │ ├── LocaleConvertUtils.java │ │ ├── LocaleConvertUtilsBean.java │ │ ├── LocaleConverter.java │ │ ├── converters │ │ │ ├── BigDecimalLocaleConverter.java │ │ │ ├── BigIntegerLocaleConverter.java │ │ │ ├── ByteLocaleConverter.java │ │ │ ├── DateLocaleConverter.java │ │ │ ├── DecimalLocaleConverter.java │ │ │ ├── DoubleLocaleConverter.java │ │ │ ├── FloatLocaleConverter.java │ │ │ ├── IntegerLocaleConverter.java │ │ │ ├── LongLocaleConverter.java │ │ │ ├── ShortLocaleConverter.java │ │ │ ├── StringLocaleConverter.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ ├── package-info.java │ │ └── sql │ │ ├── AbstractJdbcDynaClass.java │ │ ├── ResultSetDynaClass.java │ │ ├── ResultSetIterator.java │ │ ├── RowSetDynaClass.java │ │ ├── converters │ │ ├── SqlDateConverter.java │ │ ├── SqlTimeConverter.java │ │ ├── SqlTimestampConverter.java │ │ ├── locale │ │ │ ├── SqlDateLocaleConverter.java │ │ │ ├── SqlTimeLocaleConverter.java │ │ │ ├── SqlTimestampLocaleConverter.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ └── package-info.java └── javadoc │ └── overview.html ├── media └── logo.xcf ├── site ├── resources │ ├── .htaccess │ ├── download_beanutils.cgi │ ├── images │ │ └── logo.png │ └── profile.jacoco ├── site.xml └── xdoc │ ├── bean-collections.xml │ ├── building.xml │ ├── download_beanutils.xml │ ├── index.xml │ ├── issue-tracking.xml │ ├── mail-lists.xml │ ├── proposal.xml │ └── security.xml └── test └── java └── org └── apache └── commons └── beanutils2 ├── AbstractChild.java ├── AbstractParent.java ├── AlphaBean.java ├── BasicDynaBeanTest.java ├── BeanComparatorTest.java ├── BeanIntrospectionDataTest.java ├── BeanMapTest.java ├── BeanPredicateTest.java ├── BeanPropertyValueChangeConsumerTest.java ├── BeanPropertyValueEqualsPredicateTest.java ├── BeanToPropertyValueTransformerTest.java ├── BeanUtilsBeanTest.java ├── BeanUtilsBenchCase.java ├── BeanWithInnerBean.java ├── BeanificationTest.java ├── BenchBean.java ├── BetaBean.java ├── Child.java ├── ConstructorUtilsTest.java ├── ConvertUtilsTest.java ├── DefaultIntrospectionContextTest.java ├── DynaBeanMapDecoratorTest.java ├── DynaBeanUtilsTest.java ├── DynaPropertyTest.java ├── DynaPropertyUtilsTest.java ├── ExtendMapBean.java ├── FluentIntrospectionTestBean.java ├── FluentPropertyBeanIntrospectorTest.java ├── IndexedPropertyTest.java ├── IndexedTestBean.java ├── LazyDynaBeanTest.java ├── LazyDynaClassTest.java ├── LazyDynaListTest.java ├── LazyDynaMapTest.java ├── MappedPropertyChildBean.java ├── MappedPropertyChildInterface.java ├── MappedPropertyTest.java ├── MappedPropertyTestBean.java ├── MappedPropertyTestInterface.java ├── MethodUtilsTest.java ├── NestedTestBean.java ├── PassTestException.java ├── PrimitiveBean.java ├── PropertyUtilsBeanTest.java ├── PropertyUtilsBenchCase.java ├── PropertyUtilsTest.java ├── PropsFirstPropertyUtilsBean.java ├── SonOfAlphaBean.java ├── SuppressPropertiesBeanIntrospectorTest.java ├── TestBean.java ├── TestBeanPackageSubclass.java ├── TestBeanPublicSubclass.java ├── ThrowExceptionConverter.java ├── WrapDynaBeanTest.java ├── bugs ├── EnumDeclaringClassTest.java ├── Jira157Test.java ├── Jira18Test.java ├── Jira273Test.java ├── Jira298Test.java ├── Jira339Test.java ├── Jira345Test.java ├── Jira347Test.java ├── Jira349Test.java ├── Jira357Test.java ├── Jira358Test.java ├── Jira359Test.java ├── Jira368Test.java ├── Jira369Test.java ├── Jira381Test.java ├── Jira411Test.java ├── Jira422Test.java ├── Jira422bTest.java ├── Jira454Test.java ├── Jira456Test.java ├── Jira458Test.java ├── Jira463Test.java ├── Jira465Test.java ├── Jira492Test.java ├── Jira493Test.java ├── Jira509Test.java ├── Jira520Test.java ├── Jira541Test.java ├── Jira61Test.java ├── Jira87Test.java ├── Jira92Test.java └── other │ ├── Jira18BeanFactory.java │ ├── Jira273BeanFactory.java │ ├── Jira298BeanFactory.java │ ├── Jira492IndexedListsSupport.java │ ├── Jira61BeanFactory.java │ └── Jira87BeanFactory.java ├── converters ├── AbstractDateConverterTest.java ├── AbstractLocaleConverterTest.java ├── AbstractNumberConverterTest.java ├── ArrayConverterTest.java ├── BigDecimalConverterTest.java ├── BigDecimalLocaleConverterTest.java ├── BigIntegerConverterTest.java ├── BigIntegerLocaleConverterTest.java ├── BooleanConverterTest.java ├── ByteConverterTest.java ├── ByteLocaleConverterTest.java ├── CalendarConverterTest.java ├── CharacterConverterTest.java ├── ClassConverterTest.java ├── ClassReloader.java ├── ClassReloaderTest.java ├── ColorConverterTest.java ├── DateConverterTest.java ├── DateLocaleConverterTest.java ├── DimensionConverterTest.java ├── DoubleConverterTest.java ├── DoubleLocaleConverterTest.java ├── DurationConverterTest.java ├── EnumConverterTest.java ├── FileConverterTest.java ├── FloatConverterTest.java ├── FloatLocaleConverterTest.java ├── InetAddressConverterTest.java ├── IntegerConverterTest.java ├── IntegerLocaleConverterTest.java ├── LocalDateConverterTest.java ├── LocalDateTimeConverterTest.java ├── LocalTimeConverterTest.java ├── LocaleConverterTest.java ├── LongConverterTest.java ├── LongLocaleConverterTest.java ├── MemoryTest.java ├── MonthDayConverterTest.java ├── OffsetDateTimeConverterTest.java ├── OffsetTimeConverterTest.java ├── PathConverterTest.java ├── PatternConverterTest.java ├── PeriodConverterTest.java ├── PointConverterTest.java ├── ShortConverterTest.java ├── ShortLocaleConverterTest.java ├── StringConverterTest.java ├── URIConverterTest.java ├── URLConverterTest.java ├── UUIDConverterTest.java ├── YearConverterTest.java ├── YearMonthConverterTest.java ├── ZoneIdConverterTest.java ├── ZoneOffsetConverterTest.java └── ZonedDateTimeConverterTest.java ├── expression └── DefaultResolverTest.java ├── locale ├── LocaleBeanUtilsTest.java ├── LocaleBeanificationTest.java └── LocaleConvertUtilsTest.java ├── memoryleaktests ├── MemoryLeakTest.java └── pojotests │ ├── CustomInteger.java │ ├── SomeMappedPojo.java │ └── SomePojo.java ├── priv ├── PackageBean.java ├── PrivateBean.java ├── PrivateBeanFactory.java ├── PrivateBeanSubclass.java ├── PrivateDirect.java ├── PrivateIndirect.java └── PublicSubBean.java └── sql ├── DynaResultSetTest.java ├── DynaRowSetTest.java ├── TestResultSet.java ├── TestResultSetMetaData.java └── converters ├── SqlDateConverterTest.java ├── SqlTimeConverterTest.java └── SqlTimestampConverterTest.java /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | github: 17 | description: "Apache Commons Beanutils" 18 | homepage: https://commons.apache.org/beanutils/ 19 | 20 | notifications: 21 | commits: commits@commons.apache.org 22 | issues: issues@commons.apache.org 23 | pullrequests: issues@commons.apache.org 24 | jira_options: link label 25 | jobs: notifications@commons.apache.org 26 | issues_bot_dependabot: notifications@commons.apache.org 27 | pullrequests_bot_dependabot: notifications@commons.apache.org 28 | issues_bot_codecov-commenter: notifications@commons.apache.org 29 | pullrequests_bot_codecov-commenter: notifications@commons.apache.org 30 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | * text=auto 17 | -------------------------------------------------------------------------------- /.github/GH-ROBOTS.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Keeps on creating FUD PRs in test code 17 | # Does not follow Apache disclosure policies 18 | User-agent: JLLeitschuh/security-research 19 | Disallow: * 20 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | version: 2 17 | updates: 18 | - package-ecosystem: "maven" 19 | directory: "/" 20 | schedule: 21 | interval: "weekly" 22 | day: "friday" 23 | - package-ecosystem: "github-actions" 24 | directory: "/" 25 | schedule: 26 | interval: "weekly" 27 | day: "friday" 28 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated! 21 | 22 | Before you push a pull request, review this list: 23 | 24 | - [ ] Read the [contribution guidelines](CONTRIBUTING.md) for this project. 25 | - [ ] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. 26 | - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best-practice. 27 | - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. 28 | - [ ] Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge. 29 | -------------------------------------------------------------------------------- /.github/workflows/dependency-review.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: 'Dependency Review' 19 | on: [pull_request] 20 | 21 | permissions: 22 | contents: read 23 | 24 | jobs: 25 | dependency-review: 26 | runs-on: ubuntu-latest 27 | steps: 28 | - name: 'Checkout Repository' 29 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 30 | - name: 'Dependency Review PR' 31 | uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1 32 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: Java CI 17 | 18 | on: 19 | push: 20 | branches: [ master ] 21 | pull_request: 22 | branches: [ master ] 23 | 24 | permissions: 25 | contents: read 26 | 27 | jobs: 28 | build: 29 | 30 | runs-on: ubuntu-latest 31 | continue-on-error: ${{ matrix.experimental }} 32 | strategy: 33 | matrix: 34 | java: [ 8, 11, 17, 21 ] 35 | experimental: [false] 36 | include: 37 | - java: 24 38 | experimental: true 39 | - java: 25-ea 40 | experimental: true 41 | 42 | steps: 43 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 44 | with: 45 | persist-credentials: false 46 | - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 47 | with: 48 | path: ~/.m2/repository 49 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 50 | restore-keys: | 51 | ${{ runner.os }}-maven- 52 | - name: Set up JDK ${{ matrix.java }} 53 | uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1 54 | with: 55 | distribution: 'temurin' 56 | java-version: ${{ matrix.java }} 57 | - name: Build with Maven 58 | run: mvn --errors --show-version --batch-mode --no-transfer-progress -e 59 | 60 | # For Java 11, you can be more strict: -DadditionalJOption=-Xdoclint/package:-org.apache.commons.configuration2.plist 61 | -------------------------------------------------------------------------------- /.github/workflows/scorecards-analysis.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache license, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the license for the specific language governing permissions and 14 | # limitations under the license. 15 | 16 | name: "Scorecards supply-chain security" 17 | 18 | on: 19 | branch_protection_rule: 20 | schedule: 21 | - cron: "30 1 * * 6" # Weekly on Saturdays 22 | push: 23 | branches: [ "master" ] 24 | 25 | permissions: read-all 26 | 27 | jobs: 28 | 29 | analysis: 30 | 31 | name: "Scorecards analysis" 32 | runs-on: ubuntu-latest 33 | permissions: 34 | # Needed to upload the results to the code-scanning dashboard. 35 | security-events: write 36 | actions: read 37 | id-token: write # This is required for requesting the JWT 38 | contents: read # This is required for actions/checkout 39 | 40 | steps: 41 | 42 | - name: "Checkout code" 43 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 44 | with: 45 | persist-credentials: false 46 | 47 | - name: "Run analysis" 48 | uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # 2.4.2 49 | with: 50 | results_file: results.sarif 51 | results_format: sarif 52 | # A read-only PAT token, which is sufficient for the action to function. 53 | # The relevant discussion: https://github.com/ossf/scorecard-action/issues/188 54 | repo_token: ${{ secrets.GITHUB_TOKEN }} 55 | # Publish the results for public repositories to enable scorecard badges. 56 | # For more details: https://github.com/ossf/scorecard-action#publishing-results 57 | publish_results: true 58 | 59 | - name: "Upload artifact" 60 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 61 | with: 62 | name: SARIF file 63 | path: results.sarif 64 | retention-days: 5 65 | 66 | - name: "Upload to code-scanning" 67 | uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18 68 | with: 69 | sarif_file: results.sarif 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | .classpath 3 | .project 4 | .settings/ 5 | /.idea/ 6 | /commons-beanutils2.iml 7 | -------------------------------------------------------------------------------- /BUILDING.txt: -------------------------------------------------------------------------------- 1 | # Apache BeanUtils build instructions 2 | 3 | Building BeanUtils requires: 4 | 5 | - JDK 6/OpenJDK 6 or later (recommended: JDK 8) 6 | http://www.oracle.com/technetwork/java/javase/downloads/ 7 | 8 | - Apache Maven 3 or later (recommended: Maven 3.3) 9 | https://maven.apache.org/download.cgi 10 | 11 | The compiled BeanUtils JAR should work with Java 6 or later. 12 | 13 | 14 | To build target/commons-beanutils-*.jar 15 | 16 | mvn clean package 17 | 18 | or to install into your ~/.m2/repository 19 | 20 | mvn clean install 21 | 22 | 23 | You can skip the unit tests by adding the parameter 24 | 25 | -DskipTests=true 26 | 27 | 28 | 29 | To regenerate the web site (corresponding to the official 30 | https://commons.apache.org/proper/commons-beanutils/ ) do 31 | 32 | mvn clean site 33 | 34 | Note: the Apache Commons BeanUtils site should include a japicmp report for the 35 | purpose of checking API version compatibility, to enable this, use Java 7 or 36 | later and run instead: 37 | 38 | mvn clean package site -Pjapicmp 39 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html). 18 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Commons BeanUtils 2 | Copyright 2000-2025 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (https://www.apache.org/). 6 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html). 18 | -------------------------------------------------------------------------------- /src/conf/checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | bin 21 | 22 | tar.gz 23 | zip 24 | 25 | false 26 | 27 | 28 | 29 | LICENSE.txt 30 | NOTICE.txt 31 | RELEASE-NOTES.txt 32 | 33 | 34 | 35 | target 36 | 37 | 38 | *.jar 39 | 40 | 41 | 42 | target/site/apidocs 43 | apidocs 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/main/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | src 21 | 22 | tar.gz 23 | zip 24 | 25 | ${artifactId}-${version}-src 26 | 27 | 28 | 29 | build.properties.sample 30 | build.xml 31 | src/conf/checkstyle.xml 32 | src/conf/checkstyle-suppressions.xml 33 | CONTRIBUTING.md 34 | BUILDING.txt 35 | LICENSE.txt 36 | NOTICE.txt 37 | pom.xml 38 | README.md 39 | RELEASE-NOTES.txt 40 | 41 | 42 | 43 | src 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/BeanAccessLanguageException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * Thrown to indicate that the Bean Access Language cannot execute query against given bean. This is a runtime exception and access languages are 22 | * encouraged to subclass to create custom exceptions whenever appropriate. 23 | * 24 | * @since 1.7 25 | */ 26 | public class BeanAccessLanguageException extends IllegalArgumentException { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * Constructs a {@code BeanAccessLanguageException} without a detail message. 32 | */ 33 | public BeanAccessLanguageException() { 34 | } 35 | 36 | /** 37 | * Constructs a {@code BeanAccessLanguageException} without a detail message. 38 | * 39 | * @param message the detail message explaining this exception 40 | */ 41 | public BeanAccessLanguageException(final String message) { 42 | super(message); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/BeanIntrospector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2; 18 | 19 | import java.beans.IntrospectionException; 20 | 21 | /** 22 | *

23 | * Definition of an interface for components that can perform introspection on bean classes. 24 | *

25 | *

26 | * Before {@link PropertyUtils} can be used for interaction with a specific Java class, the class's properties have to be determined. This is called 27 | * introspection and is initiated automatically on demand. {@code PropertyUtils} does not perform introspection on its own, but delegates this task to 28 | * one or more objects implementing this interface. This makes it possible to customize introspection which may be useful for certain code bases using 29 | * non-standard conventions for accessing properties. 30 | *

31 | * 32 | * @since 1.9 33 | */ 34 | public interface BeanIntrospector { 35 | 36 | /** 37 | * Performs introspection on a Java class. The current class to be inspected can be queried from the passed in {@code IntrospectionContext} object. A 38 | * typical implementation has to obtain this class, determine its properties according to the rules it implements, and add them to the passed in context 39 | * object. 40 | * 41 | * @param icontext the context object for interaction with the initiator of the introspection request 42 | * @throws IntrospectionException if an error occurs during introspection 43 | */ 44 | void introspect(IntrospectionContext icontext) throws IntrospectionException; 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/ConversionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * A ConversionException indicates that a call to {@code Converter.convert()} has failed to complete successfully. 22 | * 23 | * @since 1.3 24 | */ 25 | public class ConversionException extends RuntimeException { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | /** 30 | * Constructs a new instance with a message formatted using {@link String#format(String, Object...)}. 31 | * 32 | * @param format See {@link String#format(String, Object...)}. 33 | * @param args See {@link String#format(String, Object...)}. 34 | * @return a new instance with a message formatted using {@link String#format(String, Object...)}. 35 | * @since 2.0.0 36 | */ 37 | public static ConversionException format(final String format, final Object... args) { 38 | return new ConversionException(String.format(format, args)); 39 | } 40 | 41 | /** 42 | * Constructs a new exception with the specified message. 43 | * 44 | * @param message The message describing this exception 45 | */ 46 | public ConversionException(final String message) { 47 | super(message); 48 | } 49 | 50 | /** 51 | * Constructs a new exception with the specified message and root cause. 52 | * 53 | * @param message The message describing this exception 54 | * @param cause The root cause of this exception 55 | */ 56 | public ConversionException(final String message, final Throwable cause) { 57 | super(message, cause); 58 | } 59 | 60 | /** 61 | * Constructs a new exception with the specified root cause. 62 | * 63 | * @param cause The root cause of this exception 64 | */ 65 | public ConversionException(final Throwable cause) { 66 | super(cause.getMessage()); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/Converter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | *

22 | * General purpose data type converter that can be registered and used within the BeanUtils package to manage the conversion of objects from one type to 23 | * another. 24 | *

25 | * 26 | *

27 | * Converter subclasses bundled with the BeanUtils library are required to be thread-safe, as users of the library may call conversion methods from more than 28 | * one thread simultaneously. 29 | *

30 | * 31 | *

32 | * Custom converter subclasses created by users of the library can be non-thread-safe if the application using them is single-threaded. However it is 33 | * recommended that they be written in a thread-safe manner anyway. 34 | *

35 | * 36 | * @param the convert type. 37 | * @since 1.3 38 | */ 39 | @FunctionalInterface 40 | public interface Converter { 41 | 42 | /** 43 | * Convert the specified input object into an output object of the specified type. 44 | * 45 | * @param the result type. 46 | * @param type Data type to which this value should be converted 47 | * @param value The input value to be converted 48 | * @return The converted value 49 | * @throws ConversionException if conversion cannot be performed successfully 50 | */ 51 | R convert(Class type, Object value); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/NestedNullException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * Thrown to indicate that the Bean Access Language cannot execute query against given bean since a nested bean referenced is null. 22 | * 23 | * @since 1.7 24 | */ 25 | public class NestedNullException extends BeanAccessLanguageException { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | /** 30 | * Constructs a {@code NestedNullException} without a detail message. 31 | */ 32 | public NestedNullException() { 33 | } 34 | 35 | /** 36 | * Constructs a {@code NestedNullException} without a detail message. 37 | * 38 | * @param message the detail message explaining this exception 39 | */ 40 | public NestedNullException(final String message) { 41 | super(message); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/PropertyDescriptors.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | import java.beans.PropertyDescriptor; 21 | 22 | final class PropertyDescriptors { 23 | 24 | static final PropertyDescriptor[] EMPTY_ARRAY = {}; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/TestEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * An {@code enum} test fixture. 22 | */ 23 | public enum TestEnum { 24 | 25 | /** Test fixture. */ 26 | A, 27 | 28 | /** Test fixture. */ 29 | B, 30 | 31 | /** Test fixture. */ 32 | C 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/ByteConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | /** 20 | * {@link NumberConverter} implementation that handles conversion to and from java.lang.Byte objects. 21 | *

22 | * This implementation can be configured to handle conversion either by using Byte's default String conversion, or by using a Locale's pattern or by specifying 23 | * a format pattern. See the {@link NumberConverter} documentation for further details. 24 | *

25 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 26 | * 27 | * @since 1.3 28 | */ 29 | public final class ByteConverter extends NumberConverter { 30 | 31 | /** 32 | * Constructs a java.lang.Byte Converter that throws a {@code ConversionException} if an error occurs. 33 | */ 34 | public ByteConverter() { 35 | super(false); 36 | } 37 | 38 | /** 39 | * Constructs a java.lang.Byte Converter that returns a default value if an error occurs. 40 | * 41 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 42 | */ 43 | public ByteConverter(final Byte defaultValue) { 44 | super(false, defaultValue); 45 | } 46 | 47 | /** 48 | * Constructs a java.lang.Byte Converter that returns a default value if an error occurs. 49 | * 50 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 51 | */ 52 | public ByteConverter(final Number defaultValue) { 53 | this(defaultValue.byteValue()); 54 | } 55 | 56 | /** 57 | * Gets the default type this {@code Converter} handles. 58 | * 59 | * @return The default type this {@code Converter} handles. 60 | * @since 1.8.0 61 | */ 62 | @Override 63 | protected Class getDefaultType() { 64 | return Byte.class; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/CalendarConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.util.Calendar; 20 | 21 | /** 22 | * {@link DateTimeConverter} implementation that handles conversion to and from java.util.Calendar objects. 23 | *

24 | * This implementation can be configured to handle conversion either by using a Locale's default format or by specifying a set of format patterns (note, there 25 | * is no default String conversion for Calendar). See the {@link DateTimeConverter} documentation for further details. 26 | *

27 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 28 | * 29 | * @since 1.8.0 30 | */ 31 | public final class CalendarConverter extends DateTimeConverter { 32 | 33 | /** 34 | * Constructs a java.util.Calendar Converter that throws a {@code ConversionException} if an error occurs. 35 | */ 36 | public CalendarConverter() { 37 | } 38 | 39 | /** 40 | * Constructs a java.util.Calendar Converter that returns a default value if an error occurs. 41 | * 42 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 43 | */ 44 | public CalendarConverter(final Calendar defaultValue) { 45 | super(defaultValue); 46 | } 47 | 48 | /** 49 | * Gets the default type this {@code Converter} handles. 50 | * 51 | * @return The default type this {@code Converter} handles. 52 | */ 53 | @Override 54 | protected Class getDefaultType() { 55 | return Calendar.class; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/ConverterFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.util.Objects; 20 | 21 | import org.apache.commons.beanutils2.Converter; 22 | 23 | /** 24 | *

25 | * Provides a facade for {@link Converter} implementations preventing access to any public API in the implementation, other than that specified by 26 | * {@link Converter}. 27 | *

28 | * This implementation can be used to prevent registered {@link Converter} implementations that provide configuration options from being retrieved and modified. 29 | *

30 | * 31 | * @param The converter type. 32 | * @since 1.8.0 33 | */ 34 | public final class ConverterFacade implements Converter { 35 | 36 | private final Converter converter; 37 | 38 | /** 39 | * Constructs a converter which delegates to the specified {@link Converter} implementation. 40 | * 41 | * @param converter The converter to delegate to 42 | */ 43 | public ConverterFacade(final Converter converter) { 44 | this.converter = Objects.requireNonNull(converter, "converter"); 45 | } 46 | 47 | /** 48 | * Convert the input object into an output object of the specified type by delegating to the underlying {@link Converter} implementation. 49 | * 50 | * @param type Data type to which this value should be converted 51 | * @param value The input value to be converted 52 | * @return The converted value. 53 | */ 54 | @Override 55 | public R convert(final Class type, final Object value) { 56 | return converter.convert(type, value); 57 | } 58 | 59 | /** 60 | * Provide a String representation of this facade implementation sand the underlying {@link Converter} it delegates to. 61 | * 62 | * @return A String representation of this facade implementation sand the underlying {@link Converter} it delegates to 63 | */ 64 | @Override 65 | public String toString() { 66 | return "ConverterFacade[" + converter.toString() + "]"; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/DateConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.util.Date; 20 | 21 | /** 22 | * {@link DateTimeConverter} implementation that handles conversion to and from java.util.Date objects. 23 | *

24 | * This implementation can be configured to handle conversion either by using a Locale's default format or by specifying a set of format patterns (note, there 25 | * is no default String conversion for Date). See the {@link DateTimeConverter} documentation for further details. 26 | *

27 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 28 | * 29 | * @since 1.8.0 30 | */ 31 | public final class DateConverter extends DateTimeConverter { 32 | 33 | /** 34 | * Constructs a java.util.Date Converter that throws a {@code ConversionException} if an error occurs. 35 | */ 36 | public DateConverter() { 37 | } 38 | 39 | /** 40 | * Constructs a java.util.Date Converter that returns a default value if an error occurs. 41 | * 42 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 43 | */ 44 | public DateConverter(final Date defaultValue) { 45 | super(defaultValue); 46 | } 47 | 48 | /** 49 | * Gets the default type this {@code Converter} handles. 50 | * 51 | * @return The default type this {@code Converter} handles. 52 | */ 53 | @Override 54 | protected Class getDefaultType() { 55 | return Date.class; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/DoubleConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | /** 20 | * {@link NumberConverter} implementation that handles conversion to and from java.lang.Double objects. 21 | *

22 | * This implementation can be configured to handle conversion either by using Double's default String conversion, or by using a Locale's pattern or by 23 | * specifying a format pattern. See the {@link NumberConverter} documentation for further details. 24 | *

25 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 26 | * 27 | * @since 1.3 28 | */ 29 | public final class DoubleConverter extends NumberConverter { 30 | 31 | /** 32 | * Constructs a java.lang.Double Converter that throws a {@code ConversionException} if an error occurs. 33 | */ 34 | public DoubleConverter() { 35 | super(true); 36 | } 37 | 38 | /** 39 | * Constructs a java.lang.Double Converter that returns a default value if an error occurs. 40 | * 41 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 42 | */ 43 | public DoubleConverter(final Double defaultValue) { 44 | super(true, defaultValue); 45 | } 46 | 47 | /** 48 | * Constructs a java.lang.Double Converter that returns a default value if an error occurs. 49 | * 50 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 51 | */ 52 | public DoubleConverter(final Number defaultValue) { 53 | this(defaultValue.doubleValue()); 54 | } 55 | 56 | /** 57 | * Gets the default type this {@code Converter} handles. 58 | * 59 | * @return The default type this {@code Converter} handles. 60 | * @since 1.8.0 61 | */ 62 | @Override 63 | protected Class getDefaultType() { 64 | return Double.class; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/FloatConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | /** 20 | * {@link NumberConverter} implementation that handles conversion to and from java.lang.Float objects. 21 | *

22 | * This implementation can be configured to handle conversion either by using Float's default String conversion, or by using a Locale's pattern or by specifying 23 | * a format pattern. See the {@link NumberConverter} documentation for further details. 24 | *

25 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 26 | * 27 | * @since 1.3 28 | */ 29 | public final class FloatConverter extends NumberConverter { 30 | 31 | /** 32 | * Constructs a java.lang.Float Converter that throws a {@code ConversionException} if an error occurs. 33 | */ 34 | public FloatConverter() { 35 | super(true); 36 | } 37 | 38 | /** 39 | * Constructs a java.lang.Float Converter that returns a default value if an error occurs. 40 | * 41 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 42 | */ 43 | public FloatConverter(final Float defaultValue) { 44 | super(true, defaultValue); 45 | } 46 | 47 | /** 48 | * Constructs a java.lang.Float Converter that returns a default value if an error occurs. 49 | * 50 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 51 | */ 52 | public FloatConverter(final Number defaultValue) { 53 | this(defaultValue.floatValue()); 54 | } 55 | 56 | /** 57 | * Gets the default type this {@code Converter} handles. 58 | * 59 | * @return The default type this {@code Converter} handles. 60 | * @since 1.8.0 61 | */ 62 | @Override 63 | protected Class getDefaultType() { 64 | return Float.class; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/IntegerConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | /** 20 | * {@link NumberConverter} implementation that handles conversion to and from java.lang.Integer objects. 21 | *

22 | * This implementation can be configured to handle conversion either by using Integer's default String conversion, or by using a Locale's pattern or by 23 | * specifying a format pattern. See the {@link NumberConverter} documentation for further details. 24 | *

25 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 26 | * 27 | * @since 1.3 28 | */ 29 | public final class IntegerConverter extends NumberConverter { 30 | 31 | /** 32 | * Constructs a java.lang.Integer Converter that throws a {@code ConversionException} if an error occurs. 33 | */ 34 | public IntegerConverter() { 35 | super(false); 36 | } 37 | 38 | /** 39 | * Constructs a java.lang.Integer Converter that returns a default value if an error occurs. 40 | * 41 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 42 | */ 43 | public IntegerConverter(final Integer defaultValue) { 44 | super(false, defaultValue); 45 | } 46 | 47 | /** 48 | * Constructs a java.lang.Integer Converter that returns a default value if an error occurs. 49 | * 50 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 51 | */ 52 | public IntegerConverter(final Number defaultValue) { 53 | this(defaultValue.intValue()); 54 | } 55 | 56 | /** 57 | * Gets the default type this {@code Converter} handles. 58 | * 59 | * @return The default type this {@code Converter} handles. 60 | * @since 1.8.0 61 | */ 62 | @Override 63 | protected Class getDefaultType() { 64 | return Integer.class; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.time.LocalDate; 20 | 21 | /** 22 | * {@link DateTimeConverter} implementation that handles conversion to and from java.time.LocalDate objects. 23 | *

24 | * This implementation can be configured to handle conversion either by using a Locale's default format or by specifying a set of format patterns (note, there 25 | * is no default String conversion for Calendar). See the {@link DateTimeConverter} documentation for further details. 26 | *

27 | *

28 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 29 | *

30 | * 31 | * @since 2.0 32 | * @see java.time.LocalDate 33 | */ 34 | public final class LocalDateConverter extends DateTimeConverter { 35 | 36 | /** 37 | * Constructs a java.time.LocalDate Converter that throws a {@code ConversionException} if an error occurs. 38 | */ 39 | public LocalDateConverter() { 40 | } 41 | 42 | /** 43 | * Constructs a java.time.LocalDate Converter that returns a default value if an error occurs. 44 | * 45 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 46 | */ 47 | public LocalDateConverter(final LocalDate defaultValue) { 48 | super(defaultValue); 49 | } 50 | 51 | /** 52 | * Gets the default type this {@code Converter} handles. 53 | * 54 | * @return The default type this {@code Converter} handles. 55 | */ 56 | @Override 57 | protected Class getDefaultType() { 58 | return LocalDate.class; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/LocalDateTimeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.time.LocalDateTime; 20 | 21 | /** 22 | * {@link DateTimeConverter} implementation that handles conversion to and from java.time.LocalDateTime objects. 23 | *

24 | * This implementation can be configured to handle conversion either by using a Locale's default format or by specifying a set of format patterns (note, there 25 | * is no default String conversion for Calendar). See the {@link DateTimeConverter} documentation for further details. 26 | *

27 | *

28 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 29 | *

30 | * 31 | * @since 2.0 32 | * @see java.time.LocalDateTime 33 | */ 34 | public final class LocalDateTimeConverter extends DateTimeConverter { 35 | 36 | /** 37 | * Constructs a java.time.LocalDateTime Converter that throws a {@code ConversionException} if an error occurs. 38 | */ 39 | public LocalDateTimeConverter() { 40 | } 41 | 42 | /** 43 | * Constructs a java.time.LocalDateTime Converter that returns a default value if an error occurs. 44 | * 45 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 46 | */ 47 | public LocalDateTimeConverter(final LocalDateTime defaultValue) { 48 | super(defaultValue); 49 | } 50 | 51 | /** 52 | * Gets the default type this {@code Converter} handles. 53 | * 54 | * @return The default type this {@code Converter} handles. 55 | */ 56 | @Override 57 | protected Class getDefaultType() { 58 | return LocalDateTime.class; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/LocaleConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.beanutils2.converters; 20 | 21 | import java.util.Locale; 22 | 23 | /** 24 | * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion to and from {@link Locale}. 25 | * 26 | * @since 2.0.0 27 | */ 28 | public class LocaleConverter extends AbstractConverter { 29 | 30 | /** 31 | * Construct a {@link Locale} Converter that throws a {@code ConversionException} if an error occurs. 32 | */ 33 | public LocaleConverter() { 34 | } 35 | 36 | /** 37 | * Constructs a {@link org.apache.commons.beanutils2.Converter} that will return the specified default value if a conversion error occurs. 38 | * 39 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 40 | */ 41 | public LocaleConverter(final Locale defaultValue) { 42 | super(defaultValue); 43 | } 44 | 45 | /** 46 | * Converts the specified input object into an output object of the specified type. 47 | * 48 | * @param type Data type to which this value should be converted. 49 | * @param value The String property value to convert. 50 | * @return A {@link Locale} which represents the configuration property value. 51 | * @throws NullPointerException If the value is null. 52 | */ 53 | @Override 54 | protected T convertToType(final Class type, final Object value) throws Throwable { 55 | if (Locale.class.isAssignableFrom(type)) { 56 | final String stringValue = toString(value); 57 | return type.cast(Locale.forLanguageTag(stringValue)); 58 | } 59 | 60 | throw conversionException(type, value); 61 | } 62 | 63 | /** 64 | * Gets the default type this {@code Converter} handles. 65 | * 66 | * @return The default type this {@code Converter} handles. 67 | * @since 2.0.0 68 | */ 69 | @Override 70 | protected Class getDefaultType() { 71 | return Locale.class; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/LongConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | /** 20 | * {@link NumberConverter} implementation that handles conversion to and from java.lang.Long objects. 21 | *

22 | * This implementation can be configured to handle conversion either by using Long's default String conversion, or by using a Locale's pattern or by specifying 23 | * a format pattern. See the {@link NumberConverter} documentation for further details. 24 | *

25 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 26 | * 27 | * @since 1.3 28 | */ 29 | public final class LongConverter extends NumberConverter { 30 | 31 | /** 32 | * Constructs a java.lang.Long Converter that throws a {@code ConversionException} if an error occurs. 33 | */ 34 | public LongConverter() { 35 | super(false); 36 | } 37 | 38 | /** 39 | * Constructs a java.lang.Long Converter that returns a default value if an error occurs. 40 | * 41 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 42 | */ 43 | public LongConverter(final Long defaultValue) { 44 | super(false, defaultValue); 45 | } 46 | 47 | /** 48 | * Constructs a java.lang.Long Converter that returns a default value if an error occurs. 49 | * 50 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 51 | */ 52 | public LongConverter(final Number defaultValue) { 53 | this(defaultValue.longValue()); 54 | } 55 | 56 | /** 57 | * Gets the default type this {@code Converter} handles. 58 | * 59 | * @return The default type this {@code Converter} handles. 60 | * @since 1.8.0 61 | */ 62 | @Override 63 | protected Class getDefaultType() { 64 | return Long.class; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.time.OffsetDateTime; 20 | 21 | /** 22 | * {@link DateTimeConverter} implementation that handles conversion to and from java.time.OffsetDateTime objects. 23 | *

24 | * This implementation can be configured to handle conversion either by using a Locale's default format or by specifying a set of format patterns (note, there 25 | * is no default String conversion for Calendar). See the {@link DateTimeConverter} documentation for further details. 26 | *

27 | *

28 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 29 | *

30 | * 31 | * @since 2.0 32 | * @see java.time.OffsetDateTime 33 | */ 34 | public final class OffsetDateTimeConverter extends DateTimeConverter { 35 | 36 | /** 37 | * Constructs a java.time.OffsetDateTime Converter that throws a {@code ConversionException} if an error occurs. 38 | */ 39 | public OffsetDateTimeConverter() { 40 | } 41 | 42 | /** 43 | * Constructs a java.time.OffsetDateTime Converter that returns a default value if an error occurs. 44 | * 45 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 46 | */ 47 | public OffsetDateTimeConverter(final OffsetDateTime defaultValue) { 48 | super(defaultValue); 49 | } 50 | 51 | /** 52 | * Gets the default type this {@code Converter} handles. 53 | * 54 | * @return The default type this {@code Converter} handles. 55 | */ 56 | @Override 57 | protected Class getDefaultType() { 58 | return OffsetDateTime.class; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/ShortConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | /** 20 | * {@link NumberConverter} implementation that handles conversion to and from java.lang.Short objects. 21 | *

22 | * This implementation can be configured to handle conversion either by using Short's default String conversion, or by using a Locale's pattern or by specifying 23 | * a format pattern. See the {@link NumberConverter} documentation for further details. 24 | *

25 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 26 | * 27 | * @since 1.3 28 | */ 29 | public final class ShortConverter extends NumberConverter { 30 | 31 | /** 32 | * Constructs a java.lang.Short Converter that throws a {@code ConversionException} if an error occurs. 33 | */ 34 | public ShortConverter() { 35 | super(false); 36 | } 37 | 38 | /** 39 | * Constructs a java.lang.Short Converter that returns a default value if an error occurs. 40 | * 41 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 42 | */ 43 | public ShortConverter(final Number defaultValue) { 44 | this(defaultValue.shortValue()); 45 | } 46 | 47 | /** 48 | * Constructs a java.lang.Short Converter that returns a default value if an error occurs. 49 | * 50 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 51 | */ 52 | public ShortConverter(final Short defaultValue) { 53 | super(false, defaultValue); 54 | } 55 | 56 | /** 57 | * Gets the default type this {@code Converter} handles. 58 | * 59 | * @return The default type this {@code Converter} handles. 60 | * @since 1.8.0 61 | */ 62 | @Override 63 | protected Class getDefaultType() { 64 | return Short.class; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/URIConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.net.URI; 20 | 21 | /** 22 | * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion to and from java.net.URI objects. 23 | *

24 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 25 | * 26 | * @since 2.0 27 | */ 28 | public final class URIConverter extends AbstractConverter { 29 | 30 | /** 31 | * Constructs a java.net.URI Converter that throws a {@code ConversionException} if an error occurs. 32 | */ 33 | public URIConverter() { 34 | } 35 | 36 | /** 37 | * Constructs a java.net.URI Converter that returns a default value if an error occurs. 38 | * 39 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 40 | */ 41 | public URIConverter(final URI defaultValue) { 42 | super(defaultValue); 43 | } 44 | 45 | /** 46 | *

47 | * Converts a java.net.URI or object into a String. 48 | *

49 | * 50 | * @param Target type of the conversion. 51 | * @param type Data type to which this value should be converted. 52 | * @param value The input value to be converted. 53 | * @return The converted value. 54 | * @throws Throwable if an error occurs converting to the specified type 55 | * @since 2.0 56 | */ 57 | @Override 58 | protected T convertToType(final Class type, final Object value) throws Throwable { 59 | if (URI.class.equals(type)) { 60 | return type.cast(new URI(toString(value))); 61 | } 62 | 63 | throw conversionException(type, value); 64 | } 65 | 66 | /** 67 | * Gets the default type this {@code Converter} handles. 68 | * 69 | * @return The default type this {@code Converter} handles. 70 | * @since 2.0 71 | */ 72 | @Override 73 | protected Class getDefaultType() { 74 | return URI.class; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/ZonedDateTimeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.time.ZonedDateTime; 20 | 21 | /** 22 | * {@link DateTimeConverter} implementation that handles conversion to and from java.time.ZonedDateTime objects. 23 | *

24 | * This implementation can be configured to handle conversion either by using a Locale's default format or by specifying a set of format patterns (note, there 25 | * is no default String conversion for Calendar). See the {@link DateTimeConverter} documentation for further details. 26 | *

27 | *

28 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 29 | *

30 | * 31 | * @since 2.0 32 | * @see java.time.ZonedDateTime 33 | */ 34 | public final class ZonedDateTimeConverter extends DateTimeConverter { 35 | 36 | /** 37 | * Constructs a java.time.ZonedDateTime Converter that throws a {@code ConversionException} if an error occurs. 38 | */ 39 | public ZonedDateTimeConverter() { 40 | } 41 | 42 | /** 43 | * Constructs a java.time.ZonedDateTime Converter that returns a default value if an error occurs. 44 | * 45 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 46 | */ 47 | public ZonedDateTimeConverter(final ZonedDateTime defaultValue) { 48 | super(defaultValue); 49 | } 50 | 51 | /** 52 | * Gets the default type this {@code Converter} handles. 53 | * 54 | * @return The default type this {@code Converter} handles. 55 | */ 56 | @Override 57 | protected Class getDefaultType() { 58 | return ZonedDateTime.class; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/converters/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Standard implementations of the {@link org.apache.commons.beanutils2.Converter} interface that are pre-registered with 20 | * {@link org.apache.commons.beanutils2.ConvertUtils} at startup time. 21 | */ 22 | package org.apache.commons.beanutils2.converters; 23 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/expression/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Contains the {@link org.apache.commons.beanutils2.expression.Resolver} interface and implementations. 20 | */ 21 | package org.apache.commons.beanutils2.expression; 22 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/locale/LocaleConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.locale; 19 | 20 | import org.apache.commons.beanutils2.ConversionException; 21 | import org.apache.commons.beanutils2.Converter; 22 | 23 | /** 24 | *

25 | * General purpose locale-sensitive data type converter that can be registered and used within the BeanUtils package to manage the conversion of objects from 26 | * one type to another. 27 | * 28 | * @param The converter type. 29 | */ 30 | public interface LocaleConverter extends Converter { 31 | 32 | /** 33 | * Convert the specified locale-sensitive input object into an output object of the specified type. 34 | * 35 | * @param the result type. 36 | * @param type Data type to which this value should be converted 37 | * @param value The input value to be converted 38 | * @param pattern The user-defined pattern is used for the input object formatting. 39 | * @return The converted value 40 | * @throws ConversionException if conversion cannot be performed successfully or if the target type is not supported 41 | */ 42 | R convert(Class type, Object value, String pattern); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/locale/converters/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Standard implementations of the locale-aware {@link org.apache.commons.beanutils2.locale.LocaleConverter} interface that are pre-registered with locale-aware 20 | * {@link org.apache.commons.beanutils2.locale.LocaleConvertUtils} at startup time. 21 | */ 22 | package org.apache.commons.beanutils2.locale.converters; 23 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/locale/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Locale-aware extensions of the standard BeanUtils classes. This package allows locale-dependent population of JavaBeans. 20 | */ 21 | package org.apache.commons.beanutils2.locale; 22 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/sql/converters/SqlDateConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.sql.converters; 18 | 19 | import java.sql.Date; 20 | 21 | import org.apache.commons.beanutils2.converters.DateTimeConverter; 22 | 23 | /** 24 | * {@link DateTimeConverter} implementation that handles conversion to and from java.sql.Date objects. 25 | *

26 | * This implementation can be configured to handle conversion either by using java.sql.Date's default String conversion, or by using a Locale's default format 27 | * or by specifying a set of format patterns. See the {@link DateTimeConverter} documentation for further details. 28 | *

29 | * Can be configured to either return a default value or throw a {@code ConversionException} if a conversion error occurs. 30 | * 31 | * @since 1.3 32 | */ 33 | public final class SqlDateConverter extends DateTimeConverter { 34 | 35 | /** 36 | * Constructs a java.sql.Date Converter that throws a {@code ConversionException} if an error occurs. 37 | */ 38 | public SqlDateConverter() { 39 | } 40 | 41 | /** 42 | * Constructs a java.sql.Date Converter that returns a default value if an error occurs. 43 | * 44 | * @param defaultValue The default value to be returned if the value to be converted is missing or an error occurs converting the value. 45 | */ 46 | public SqlDateConverter(final Date defaultValue) { 47 | super(defaultValue); 48 | } 49 | 50 | /** 51 | * Gets the default type this {@code Converter} handles. 52 | * 53 | * @return The default type this {@code Converter} handles. 54 | * @since 1.8.0 55 | */ 56 | @Override 57 | protected Class getDefaultType() { 58 | return Date.class; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/sql/converters/locale/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Contains code that relies on the {@link java.sql} module. 20 | */ 21 | package org.apache.commons.beanutils2.sql.converters.locale; 22 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/sql/converters/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Contains code that relies on the {@link java.sql} module. 20 | */ 21 | package org.apache.commons.beanutils2.sql.converters; 22 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/beanutils2/sql/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Contains code that relies on the {@link java.sql} module. 20 | */ 21 | package org.apache.commons.beanutils2.sql; 22 | -------------------------------------------------------------------------------- /src/main/javadoc/overview.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | Overview Documentation for Apache Commons BeanUtils 20 | 21 | 22 |

The Bean Introspection Utilities component of the Apache Commons 23 | subproject offers low-level utility classes that assist in getting and setting 24 | property values on Java classes that follow the naming design patterns outlined 25 | in the JavaBeans Specification, as well as mechanisms for dynamically defining 26 | and accessing bean properties.

27 | 28 |

See the 29 | 30 | Package Description for the org.apache.commons.beanutils2 31 | package for more information.

32 | 33 | 34 | -------------------------------------------------------------------------------- /src/media/logo.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-beanutils/732d4940f96308e5e8718c18136ee13579897b4e/src/media/logo.xcf -------------------------------------------------------------------------------- /src/site/resources/.htaccess: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | AddCharset utf-8 .txt .html 17 | -------------------------------------------------------------------------------- /src/site/resources/download_beanutils.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Just call the standard mirrors.cgi script. It will use download.html 3 | # as the input template. 4 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* -------------------------------------------------------------------------------- /src/site/resources/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-beanutils/732d4940f96308e5e8718c18136ee13579897b4e/src/site/resources/images/logo.png -------------------------------------------------------------------------------- /src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // https://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/AbstractChild.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | */ 22 | public class AbstractChild implements Child { 23 | 24 | private String name; 25 | 26 | @Override 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | protected void setName(final String name) { 32 | this.name = name; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/AbstractParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | */ 22 | public abstract class AbstractParent { 23 | 24 | private Child child; 25 | 26 | public Child getChild() { 27 | return child; 28 | } 29 | 30 | public String testAddChild(final Child child) { 31 | this.child = child; 32 | return child.getName(); 33 | } 34 | 35 | /** 36 | * Method which matches signature but which has wrong parameters 37 | */ 38 | public String testAddChild(final String badParameter) { 39 | return null; 40 | } 41 | 42 | public String testAddChild2(final String ignore, final Child child) { 43 | this.child = child; 44 | return child.getName(); 45 | } 46 | 47 | /** 48 | * Method which matches signature but which has wrong parameters 49 | */ 50 | public String testAddChild2(final String ignore, final String badParameter) { 51 | return null; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/AlphaBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | */ 22 | public class AlphaBean extends AbstractParent implements Child { 23 | 24 | private String name; 25 | 26 | public AlphaBean() { 27 | } 28 | 29 | public AlphaBean(final String name) { 30 | setName(name); 31 | } 32 | 33 | /** 34 | * Used for testing that correct exception is thrown. 35 | */ 36 | public void bogus(final String badParameter) { 37 | // noop 38 | } 39 | 40 | @Override 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(final String name) { 46 | this.name = name; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/BeanPredicateTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertFalse; 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | import java.util.function.Predicate; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Unit test for {@link BeanPredicate} 29 | */ 30 | public class BeanPredicateTest { 31 | 32 | @Test 33 | public void testEqual() { 34 | final Predicate p = s -> s.equals("foo"); 35 | final BeanPredicate predicate = new BeanPredicate<>("stringProperty", p); 36 | assertTrue(predicate.test(new TestBean("foo"))); 37 | assertFalse(predicate.test(new TestBean("bar"))); 38 | } 39 | 40 | @Test 41 | public void testInstanceOf() { 42 | final Predicate p = String.class::isInstance; 43 | final BeanPredicate predicate = new BeanPredicate<>("stringProperty", p); 44 | assertTrue(predicate.test(new TestBean("foo"))); 45 | assertTrue(predicate.test(new TestBean("bar"))); 46 | } 47 | 48 | @Test 49 | public void testNotEqual() { 50 | final Predicate p = s -> !s.equals("foo"); 51 | final BeanPredicate predicate = new BeanPredicate<>("stringProperty", p); 52 | assertFalse(predicate.test(new TestBean("foo"))); 53 | assertTrue(predicate.test(new TestBean("bar"))); 54 | } 55 | 56 | @Test 57 | public void testNull() { 58 | final Predicate p = s -> s == null; 59 | final BeanPredicate predicate = new BeanPredicate<>("stringProperty", p); 60 | final String nullString = null; 61 | assertTrue(predicate.test(new TestBean(nullString))); 62 | assertFalse(predicate.test(new TestBean("bar"))); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/BeanWithInnerBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | import java.util.Properties; 21 | 22 | /** 23 | * Bean with inner bean. 24 | */ 25 | public class BeanWithInnerBean { 26 | public class InnerBean { 27 | private final Properties fish = new Properties(); 28 | 29 | public String getFish(final String key) { 30 | return fish.getProperty(key); 31 | } 32 | 33 | public void setFish(final String key, final String value) { 34 | fish.setProperty(key, value); 35 | } 36 | } 37 | 38 | private final InnerBean innerBean = new InnerBean(); 39 | 40 | public BeanWithInnerBean() { 41 | } 42 | 43 | public InnerBean getInnerBean() { 44 | return innerBean; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/BetaBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | */ 22 | public class BetaBean extends AbstractChild { 23 | 24 | private String secret = "utah"; 25 | 26 | public BetaBean(final String name) { 27 | setName(name); 28 | } 29 | 30 | public String getSecret() { 31 | return secret; 32 | } 33 | 34 | public void setNoGetterMappedProperty(final String secret, final String key) { 35 | this.secret = "MAP:" + secret; 36 | } 37 | 38 | public void setNoGetterProperty(final String secret) { 39 | this.secret = secret; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/Child.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | */ 22 | public interface Child { 23 | 24 | String getName(); 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/ExtendMapBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | import java.util.Hashtable; 21 | 22 | /** 23 | * Used to test 24 | */ 25 | 26 | public class ExtendMapBean extends Hashtable { 27 | 28 | private String dbName = "[UNSET]"; 29 | 30 | public ExtendMapBean() { 31 | } 32 | 33 | public String getUnusuallyNamedProperty() { 34 | return dbName; 35 | } 36 | 37 | public void setUnusuallyNamedProperty(final String dbName) { 38 | this.dbName = dbName; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/FluentIntrospectionTestBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2; 18 | 19 | /** 20 | * A bean class used for tests of introspection. 21 | */ 22 | public class FluentIntrospectionTestBean extends AlphaBean { 23 | private String stringProperty; 24 | 25 | private String fluentGetProperty; 26 | 27 | public String getFluentGetProperty() { 28 | return fluentGetProperty; 29 | } 30 | 31 | public String getStringProperty() { 32 | return stringProperty; 33 | } 34 | 35 | public FluentIntrospectionTestBean setFluentGetProperty(final String fluentGetProperty) { 36 | this.fluentGetProperty = fluentGetProperty; 37 | return this; 38 | } 39 | 40 | public FluentIntrospectionTestBean setFluentProperty(final String value) { 41 | setStringProperty(value); 42 | return this; 43 | } 44 | 45 | public void setStringProperty(final String stringProperty) { 46 | this.stringProperty = stringProperty; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/MappedPropertyChildBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * Inherited Mapped property test bean. 22 | */ 23 | 24 | public class MappedPropertyChildBean extends MappedPropertyTestBean { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/MappedPropertyChildInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * Test Child Interface 22 | */ 23 | 24 | public interface MappedPropertyChildInterface extends MappedPropertyTestInterface { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/MappedPropertyTestInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * Test Interface 22 | */ 23 | 24 | public interface MappedPropertyTestInterface { 25 | 26 | String getMapproperty(String key); 27 | 28 | void setMapproperty(String key, String value); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/NestedTestBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * Specialist test bean for complex nested properties. 22 | */ 23 | 24 | public class NestedTestBean { 25 | 26 | private String name; 27 | 28 | private String testString = "NOT SET"; 29 | 30 | private boolean testBoolean; 31 | 32 | private NestedTestBean[] indexedBeans; 33 | 34 | private NestedTestBean simpleBean; 35 | 36 | public NestedTestBean(final String name) { 37 | setName(name); 38 | } 39 | 40 | public NestedTestBean getIndexedProperty(final int index) { 41 | return this.indexedBeans[index]; 42 | } 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | public NestedTestBean getSimpleBeanProperty() { 49 | return simpleBean; 50 | } 51 | 52 | public boolean getTestBoolean() { 53 | return testBoolean; 54 | } 55 | 56 | public String getTestString() { 57 | return testString; 58 | } 59 | 60 | public void init() { 61 | indexedBeans = new NestedTestBean[5]; 62 | indexedBeans[0] = new NestedTestBean("Bean@0"); 63 | indexedBeans[1] = new NestedTestBean("Bean@1"); 64 | indexedBeans[2] = new NestedTestBean("Bean@2"); 65 | indexedBeans[3] = new NestedTestBean("Bean@3"); 66 | indexedBeans[4] = new NestedTestBean("Bean@4"); 67 | 68 | simpleBean = new NestedTestBean("Simple Property Bean"); 69 | } 70 | 71 | public void setIndexedProperty(final int index, final NestedTestBean value) { 72 | this.indexedBeans[index] = value; 73 | } 74 | 75 | public void setName(final String name) { 76 | this.name = name; 77 | } 78 | 79 | public void setTestBoolean(final boolean testBoolean) { 80 | this.testBoolean = testBoolean; 81 | } 82 | 83 | public void setTestString(final String testString) { 84 | this.testString = testString; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/PassTestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * Just a runtime exception. Useful for check that a method is called. 22 | */ 23 | public class PassTestException extends RuntimeException { 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/PrimitiveBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * Bean that has primitive properties 22 | */ 23 | public class PrimitiveBean { 24 | 25 | private float _float; 26 | private double _double; 27 | private boolean _boolean; 28 | private long _long; 29 | private int _int; 30 | 31 | public boolean getBoolean() { 32 | return _boolean; 33 | } 34 | 35 | public double getDouble() { 36 | return _double; 37 | } 38 | 39 | public float getFloat() { 40 | return _float; 41 | } 42 | 43 | public int getInt() { 44 | return _int; 45 | } 46 | 47 | public long getLong() { 48 | return _long; 49 | } 50 | 51 | public void setBoolean(final boolean _boolean) { 52 | this._boolean = _boolean; 53 | } 54 | 55 | public void setDouble(final double _double) { 56 | this._double = _double; 57 | } 58 | 59 | public void setFloat(final float _float) { 60 | this._float = _float; 61 | } 62 | 63 | public void setInt(final int _int) { 64 | this._int = _int; 65 | } 66 | 67 | public void setLong(final long _long) { 68 | this._long = _long; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/PropertyUtilsBeanTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.junit.jupiter.api.Assertions.assertNull; 22 | import static org.junit.jupiter.api.Assertions.assertThrows; 23 | 24 | import org.apache.commons.beanutils2.expression.Resolver; 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link PropertyUtilsBean}. 29 | */ 30 | public class PropertyUtilsBeanTest { 31 | 32 | @Test 33 | public void testGetMappedPropertyDescriptors() throws Exception { 34 | assertNull(new PropertyUtilsBean().getMappedPropertyDescriptors((Object) null)); 35 | assertNull(new PropertyUtilsBean().getMappedPropertyDescriptors((Class) null)); 36 | } 37 | 38 | @Test 39 | public void testGetPropertyDescriptor() throws Exception { 40 | assertThrows(NullPointerException.class, () -> new PropertyUtilsBean().getPropertyDescriptor((Object) null, null)); 41 | assertThrows(NullPointerException.class, () -> new PropertyUtilsBean().getPropertyDescriptor("", null)); 42 | } 43 | 44 | @Test 45 | public void testGetPropertyEditorClass() throws Exception { 46 | assertThrows(NullPointerException.class, () -> new PropertyUtilsBean().getPropertyEditorClass(null, "")); 47 | assertThrows(NullPointerException.class, () -> new PropertyUtilsBean().getPropertyEditorClass("", null)); 48 | } 49 | 50 | @Test 51 | public void testSetResolver() throws Exception { 52 | final PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); 53 | final Resolver resolver = propertyUtilsBean.getResolver(); 54 | assertNotNull(resolver); 55 | propertyUtilsBean.setResolver(null); 56 | assertNotNull(resolver); 57 | propertyUtilsBean.setResolver(resolver); 58 | assertEquals(resolver, propertyUtilsBean.getResolver()); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/SonOfAlphaBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | */ 22 | public class SonOfAlphaBean extends AlphaBean { 23 | 24 | public SonOfAlphaBean(final String name) { 25 | super(name); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/TestBeanPackageSubclass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * This is a package private subclass of TestBean. All of our properties should still be accessible via reflection. 22 | */ 23 | 24 | final class TestBeanPackageSubclass extends TestBean { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/TestBeanPublicSubclass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * This is a public subclass of TestBean. All of our properties should still be accessible via reflection. 22 | */ 23 | 24 | public class TestBeanPublicSubclass extends TestBean { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/ThrowExceptionConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2; 19 | 20 | /** 21 | * Converter implementation that throws a {@code PassTestException} when convert is called. The idea is that catching this exception is a clear signal that this 22 | * method has been called. 23 | */ 24 | public class ThrowExceptionConverter implements Converter { 25 | 26 | @Override 27 | public R convert(final Class type, final Object value) { 28 | throw new PassTestException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira358Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertThrows; 20 | 21 | import org.apache.commons.beanutils2.PropertyUtils; 22 | import org.apache.commons.beanutils2.TestBean; 23 | import org.junit.jupiter.api.AfterEach; 24 | import org.junit.jupiter.api.BeforeEach; 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * @see https://issues.apache.org/jira/browse/BEANUTILS-358 29 | */ 30 | public class Jira358Test { 31 | 32 | /** 33 | * Sets up. 34 | * 35 | * @throws Exception 36 | */ 37 | @BeforeEach 38 | protected void setUp() throws Exception { 39 | } 40 | 41 | /** 42 | * Tear Down. 43 | * 44 | * @throws Exception 45 | */ 46 | @AfterEach 47 | protected void tearDown() throws Exception { 48 | } 49 | 50 | /** 51 | * Test {@link PropertyUtils#getIndexedProperty(Object, String, int)} 52 | */ 53 | @Test 54 | public void testPropertyUtils_getIndexedProperty_Array() throws Exception { 55 | 56 | final TestBean bean = new TestBean(); 57 | assertThrows(ArrayIndexOutOfBoundsException.class, () -> PropertyUtils.getIndexedProperty(bean, "intArray", bean.getIntArray().length)); 58 | } 59 | 60 | /** 61 | * Test {@link PropertyUtils#getIndexedProperty(Object, String, int)} 62 | */ 63 | @Test 64 | public void testPropertyUtils_getIndexedProperty_List() throws Exception { 65 | 66 | final TestBean bean = new TestBean(); 67 | assertThrows(IndexOutOfBoundsException.class, () -> PropertyUtils.getIndexedProperty(bean, "listIndexed", bean.getListIndexed().size())); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira368Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertThrows; 20 | 21 | import org.apache.commons.beanutils2.BeanUtils; 22 | import org.junit.jupiter.api.AfterEach; 23 | import org.junit.jupiter.api.BeforeEach; 24 | import org.junit.jupiter.api.Test; 25 | 26 | /** 27 | * @see https://issues.apache.org/jira/browse/BEANUTILS-368 28 | */ 29 | public class Jira368Test { 30 | 31 | /** 32 | * Sets up. 33 | * 34 | * @throws Exception 35 | */ 36 | @BeforeEach 37 | protected void setUp() throws Exception { 38 | } 39 | 40 | /** 41 | * Tear Down. 42 | * 43 | * @throws Exception 44 | */ 45 | @AfterEach 46 | protected void tearDown() throws Exception { 47 | } 48 | 49 | /** 50 | * Test {@link BeanUtils} setProperty() with Null value 51 | */ 52 | @Test 53 | public void testBeanUtilsSetProperty_NullBean() throws Exception { 54 | assertThrows(NullPointerException.class, () -> BeanUtils.setProperty(null, "foo", "bar")); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira381Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import java.lang.reflect.Method; 22 | 23 | import org.apache.commons.beanutils2.MethodUtils; 24 | import org.junit.jupiter.api.Test; 25 | 26 | /** 27 | * MethodUtils's getMatchingAccessibleMethod() does not correctly handle inheritance and method overloading. 28 | * 29 | * @see https://issues.apache.org/jira/browse/BEANUTILS-381 30 | */ 31 | public class Jira381Test { 32 | 33 | /** 34 | * Test object. 35 | */ 36 | public class TestObject { 37 | } 38 | 39 | /** 40 | * Used to match performop with test object 41 | */ 42 | public class TestObjectSubclass extends TestObject { 43 | } 44 | 45 | /** 46 | * Test bean. 47 | */ 48 | public class TestServiceBean { 49 | 50 | /** 51 | * Generic object method 52 | */ 53 | public void performOp(final Object o) { 54 | } 55 | 56 | /** 57 | * Object method 58 | */ 59 | public void performOp(final TestObject o) { 60 | } 61 | } 62 | 63 | /** 64 | * Test with an private class that overrides a public method of a "grand parent" public class. 65 | *

66 | * See Jira issue# BEANUTILS-381. 67 | */ 68 | @Test 69 | public void testIssue_BEANUTILS_381_getMatchingAccessibleMethod() { 70 | 71 | final Class target = TestServiceBean.class; 72 | final String methodName = "performOp"; 73 | final Class[] runtimeClasses = { TestObjectSubclass.class }; 74 | 75 | final Method returned = MethodUtils.getMatchingAccessibleMethod(target, methodName, runtimeClasses); 76 | 77 | assertEquals(target, returned.getDeclaringClass()); 78 | assertEquals(methodName, returned.getName()); 79 | assertEquals(TestObject.class, returned.getParameterTypes()[0]); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira411Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import org.apache.commons.beanutils2.BeanUtilsBean; 20 | import org.junit.jupiter.api.BeforeEach; 21 | import org.junit.jupiter.api.Test; 22 | 23 | /** 24 | * BeanUtilsBean.setProperty throws IllegalArgumentException if getter of nested property returns null 25 | * 26 | * @see https://issues.apache.org/jira/browse/BEANUTILS-411 27 | */ 28 | public class Jira411Test { 29 | 30 | public class DummyBean { 31 | 32 | private String imgLink; 33 | 34 | public String getImgLink() { 35 | return imgLink; 36 | } 37 | 38 | public void setImgLink(final String imgLink) { 39 | this.imgLink = imgLink; 40 | } 41 | } 42 | 43 | private BeanUtilsBean instance; 44 | 45 | private DummyBean testBean; 46 | 47 | @BeforeEach 48 | protected void setUp() throws Exception { 49 | instance = new BeanUtilsBean(); 50 | testBean = new DummyBean(); 51 | } 52 | 53 | @Test 54 | public void testSetProperty() throws Exception { 55 | instance.setProperty(testBean, "imgLink.x", "1"); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira422bTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.apache.commons.beanutils2.PropertyUtils; 22 | import org.junit.jupiter.api.Test; 23 | 24 | final class FirstChildBeanB extends RootBeanB { 25 | } 26 | 27 | /** 28 | * Variant of {@link Jira422Test} that is compatible with BEANUTILS-492 29 | * 30 | * @see BEANUTILS-422 31 | * @see BEANUTILS-492 32 | */ 33 | public class Jira422bTest { 34 | 35 | @Test 36 | public void testRootBean() throws Exception { 37 | final RootBeanB bean = new FirstChildBeanB(); 38 | final Class propertyType = PropertyUtils.getPropertyType(bean, "file[0]"); 39 | assertEquals(String.class.getName(), propertyType.getName()); 40 | } 41 | 42 | @Test 43 | public void testSecondChildBean() throws Exception { 44 | final RootBeanB bean = new SecondChildBeanB(); 45 | final Class propertyType = PropertyUtils.getPropertyType(bean, "file[0]"); 46 | assertEquals(String.class.getName(), propertyType.getName()); 47 | } 48 | 49 | } 50 | 51 | class RootBeanB { 52 | 53 | private String[] file; 54 | 55 | public String[] getFile() { 56 | return file; 57 | } 58 | 59 | public String getFile(final int i) { 60 | return file[i]; 61 | } 62 | 63 | public void setFile(final int i, final String file) { 64 | this.file[i] = file; 65 | } 66 | 67 | public void setFile(final String[] file) { 68 | this.file = file; 69 | } 70 | 71 | } 72 | 73 | final class SecondChildBeanB extends RootBeanB { 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira454Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertNull; 20 | 21 | import java.util.Date; 22 | 23 | import org.apache.commons.beanutils2.BeanUtils; 24 | import org.junit.jupiter.api.Test; 25 | 26 | /** 27 | * copyProperties() throws a ConversionException : No value specified for 'Date' when the field is a java.util.Date with a null value 28 | */ 29 | public class Jira454Test { 30 | public static class TestBean { 31 | private Date createdAt; 32 | 33 | public Date getCreatedAt() { 34 | return createdAt; 35 | } 36 | 37 | public void setCreatedAt(final Date createdAt) { 38 | this.createdAt = createdAt; 39 | } 40 | } 41 | 42 | @Test 43 | public void testCopyProperties() throws Exception { 44 | final TestBean bean = new TestBean(); 45 | final TestBean b2 = new TestBean(); 46 | BeanUtils.copyProperties(b2, bean); 47 | assertNull(b2.getCreatedAt(), "Got a creation date"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira458Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertNull; 20 | 21 | import java.util.Locale; 22 | 23 | import org.apache.commons.beanutils2.Converter; 24 | import org.apache.commons.beanutils2.locale.converters.IntegerLocaleConverter; 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * BaseLocaleConverter.checkConversionResult() fails with ConversionException when result is null when it should not. 29 | * 30 | * @see https://issues.apache.org/jira/browse/BEANUTILS-458 31 | */ 32 | public class Jira458Test { 33 | /** 34 | * Helper method for testing a conversion with null as default. 35 | * 36 | * @param input the input string 37 | */ 38 | private void checkConversionWithNullDefault(final String input) { 39 | // final Converter converter = new IntegerLocaleConverter(null, Locale.US); 40 | final Converter converter = IntegerLocaleConverter.builder().setUseDefault(true).setLocale(Locale.US).get(); 41 | assertNull(converter.convert(Integer.class, input), "Wrong result"); 42 | } 43 | 44 | /** 45 | * Tests a conversion passing in an empty string. 46 | */ 47 | @Test 48 | public void testConversionWithNullDefaultEmptyString() { 49 | checkConversionWithNullDefault(""); 50 | } 51 | 52 | /** 53 | * Tests a conversion passing in null. 54 | */ 55 | @Test 56 | public void testConversionWithNullDefaultNullInput() { 57 | checkConversionWithNullDefault(null); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira463Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertThrows; 20 | 21 | import org.apache.commons.beanutils2.AlphaBean; 22 | import org.apache.commons.beanutils2.BeanUtilsBean; 23 | import org.apache.commons.beanutils2.SuppressPropertiesBeanIntrospector; 24 | import org.junit.jupiter.api.Test; 25 | 26 | /** 27 | * Class loader vulnerability in DefaultResolver 28 | * 29 | * @see https://issues.apache.org/jira/browse/BEANUTILS-463 30 | */ 31 | public class Jira463Test { 32 | /** 33 | * Tests that with a specialized {@code BeanIntrospector} implementation the class property can be suppressed. 34 | */ 35 | @Test 36 | public void testSuppressClassProperty() throws Exception { 37 | final BeanUtilsBean bub = new BeanUtilsBean(); 38 | bub.getPropertyUtils().addBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS); 39 | final AlphaBean bean = new AlphaBean(); 40 | assertThrows(NoSuchMethodException.class, () -> bub.getProperty(bean, "class")); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira493Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.apache.commons.beanutils2.BeanUtilsBean; 22 | import org.apache.commons.beanutils2.LazyDynaBean; 23 | import org.junit.jupiter.api.Test; 24 | 25 | /** 26 | * Test setting indexed properties on dynabeans 27 | * 28 | * @see BEANUTILS-493 29 | */ 30 | 31 | public class Jira493Test { 32 | 33 | @Test 34 | public void testIndexedProperties() throws Exception { 35 | final LazyDynaBean lazyDynaBean = new LazyDynaBean(); 36 | final BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); 37 | beanUtilsBean.setProperty(lazyDynaBean, "x[0]", "x1"); 38 | beanUtilsBean.setProperty(lazyDynaBean, "x[1]", "x2"); 39 | final Object x = lazyDynaBean.get("x"); 40 | assertEquals("[x1, x2]", x.toString()); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira520Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | import static org.junit.jupiter.api.Assertions.assertThrows; 21 | 22 | import org.apache.commons.beanutils2.AlphaBean; 23 | import org.apache.commons.beanutils2.BeanUtilsBean; 24 | import org.apache.commons.beanutils2.SuppressPropertiesBeanIntrospector; 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Fix CVE: https://nvd.nist.gov/vuln/detail/CVE-2014-0114 29 | * 30 | * @see https://issues.apache.org/jira/browse/BEANUTILS-520 31 | */ 32 | public class Jira520Test { 33 | 34 | /** 35 | * Allow opt-out to make your app less secure but allow access to "class". 36 | */ 37 | @Test 38 | public void testAllowAccessToClassProperty() throws Exception { 39 | final BeanUtilsBean bub = new BeanUtilsBean(); 40 | bub.getPropertyUtils().removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS); 41 | final AlphaBean bean = new AlphaBean(); 42 | final String result = bub.getProperty(bean, "class"); 43 | assertEquals("org.apache.commons.beanutils2.AlphaBean", result, "Class property should have been accessed"); 44 | } 45 | 46 | /** 47 | * By default opt-in to security that does not allow access to "class". 48 | */ 49 | @Test 50 | public void testSuppressClassPropertyByDefault() throws Exception { 51 | final BeanUtilsBean bub = new BeanUtilsBean(); 52 | final AlphaBean bean = new AlphaBean(); 53 | assertThrows(NoSuchMethodException.class, () -> bub.getProperty(bean, "class")); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira87Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.apache.commons.beanutils2.PropertyUtils; 22 | import org.apache.commons.beanutils2.bugs.other.Jira87BeanFactory; 23 | import org.apache.commons.logging.Log; 24 | import org.apache.commons.logging.LogFactory; 25 | import org.junit.jupiter.api.AfterEach; 26 | import org.junit.jupiter.api.BeforeEach; 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Test case for Jiar issue# BEANUTILS-87. 31 | * 32 | *

33 | * In BeanUtils 1.7.0 a "package friendly" implementation of a public interface with defined a "mapped property" caused an {@link IllegalAccessException} to be 34 | * thrown by PropertyUtils's getMappedProperty method. 35 | * 36 | *

37 | * This test case demonstrates the issue. 38 | * 39 | * @see https://issues.apache.org/jira/browse/BEANUTILS-87 40 | */ 41 | public class Jira87Test { 42 | 43 | private static final Log LOG = LogFactory.getLog(Jira87Test.class); 44 | 45 | /** 46 | * Sets up. 47 | * 48 | * @throws Exception 49 | */ 50 | @BeforeEach 51 | protected void setUp() throws Exception { 52 | } 53 | 54 | /** 55 | * Tear Down. 56 | * 57 | * @throws Exception 58 | */ 59 | @AfterEach 60 | protected void tearDown() throws Exception { 61 | } 62 | 63 | /** 64 | * Interface definition with a mapped property 65 | */ 66 | @Test 67 | public void testJira87() throws Exception { 68 | 69 | final Jira87BeanFactory.PublicMappedInterface bean = Jira87BeanFactory.createMappedPropertyBean(); 70 | // The test impl. returns the key value 71 | assertEquals("foo", PropertyUtils.getMappedProperty(bean, "value(foo)")); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/Jira92Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs; 18 | 19 | import org.apache.commons.beanutils2.PropertyUtils; 20 | import org.apache.commons.beanutils2.TestBean; 21 | import org.junit.jupiter.api.Test; 22 | 23 | /** 24 | * Test case for Jira issue# BEANUTILS-92. 25 | * 26 | * @see https://issues.apache.org/jira/browse/BEANUTILS-92 27 | */ 28 | public class Jira92Test { 29 | 30 | /** 31 | * Test bean which has only indexed setter 32 | */ 33 | public static class Jira92TestBean { 34 | 35 | private final java.util.Date[] dateArrayProperty = new java.util.Date[10]; 36 | 37 | /** 38 | * Indexed Setter. 39 | * 40 | * @param index index 41 | * @param date indexed value to set 42 | */ 43 | public void setDateArrayProperty(final int index, final java.util.Date date) { 44 | this.dateArrayProperty[index] = date; 45 | } 46 | } 47 | 48 | /** 49 | * Test copy properties where the target bean only has an indexed setter. 50 | */ 51 | @Test 52 | public void testIssue_BEANUTILS_92_copyProperties_indexed_only_setter() throws Exception { 53 | PropertyUtils.copyProperties(new Jira92TestBean(), new TestBean()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/other/Jira298BeanFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs.other; 18 | 19 | import org.apache.commons.beanutils2.bugs.Jira298Test; 20 | 21 | /** 22 | * Factory which creates beans for {@link Jira298Test}. 23 | */ 24 | public class Jira298BeanFactory { 25 | 26 | static class BaseX { 27 | private String name = "BaseX name value"; 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(final String name) { 34 | this.name = name; 35 | } 36 | } 37 | 38 | static class ImplX extends BaseX implements IX { 39 | } 40 | 41 | public interface IX { 42 | String getName(); 43 | 44 | void setName(String name); 45 | } 46 | 47 | /** 48 | * Factory method which creates ImplX. 49 | * 50 | * @return a new ImplX. 51 | */ 52 | public static IX createImplX() { 53 | return new ImplX(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/other/Jira492IndexedListsSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs.other; 18 | 19 | import java.beans.BeanInfo; 20 | import java.beans.IndexedPropertyDescriptor; 21 | import java.beans.IntrospectionException; 22 | import java.beans.Introspector; 23 | import java.beans.PropertyDescriptor; 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | /** 28 | * Test if BeanInfo supports index properties for java.util.List 29 | *

30 | * This was supported by Java until Java 8 (BEANUTILS-492). 31 | * 32 | * @see BEANUTILS-492 33 | */ 34 | public class Jira492IndexedListsSupport { 35 | public static class IndexedBean { 36 | private List someList = new ArrayList<>(); 37 | 38 | public List getSomeList() { 39 | return someList; 40 | } 41 | 42 | public String getSomeList(final int i) { 43 | return someList.get(i); 44 | } 45 | 46 | public void setSomeList(final int i, final String value) { 47 | someList.set(i, value); 48 | } 49 | 50 | public void setSomeList(final List someList) { 51 | this.someList = someList; 52 | } 53 | } 54 | 55 | public static boolean supportsIndexedLists() throws IntrospectionException { 56 | final BeanInfo beanInfo = Introspector.getBeanInfo(IndexedBean.class); 57 | for (final PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) { 58 | if (pd.getName().equals("someList")) { 59 | return pd instanceof IndexedPropertyDescriptor; 60 | } 61 | } 62 | throw new IllegalStateException("Could not find PropertyDescriptor for 'file'"); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/bugs/other/Jira87BeanFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.bugs.other; 18 | 19 | import org.apache.commons.beanutils2.bugs.Jira87Test; 20 | 21 | /** 22 | * Factory which creates beans for {@link Jira87Test}. 23 | */ 24 | public class Jira87BeanFactory { 25 | 26 | /* =============== Package Friendly implementation of public interface =============== */ 27 | static class PackageMappedImpl implements PublicMappedInterface { 28 | 29 | /** 30 | * This implementation returns the key value. 31 | * 32 | * @param key The key of the mapped value 33 | * @return The key value 34 | */ 35 | @Override 36 | public Object getValue(final String key) { 37 | return key; 38 | } 39 | 40 | } 41 | 42 | /* =================== Public interface with Mapped Property ========================= */ 43 | /** 44 | * Public interface with a mapped property. 45 | */ 46 | public interface PublicMappedInterface { 47 | 48 | /** 49 | * Mapped Property method 50 | * 51 | * @param key The key of the mapped value 52 | * @return The value 53 | */ 54 | Object getValue(String key); 55 | 56 | } 57 | 58 | /** 59 | * Factory method which creates beans bean with mapped method. 60 | * 61 | * @return The the mapped property bean instance 62 | */ 63 | public static PublicMappedInterface createMappedPropertyBean() { 64 | return new PackageMappedImpl(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/CalendarConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.util.Calendar; 20 | 21 | /** 22 | * Test Case for the CalendarConverter class. 23 | */ 24 | public class CalendarConverterTest extends AbstractDateConverterTest { 25 | 26 | /** 27 | * Gets the expected type 28 | * 29 | * @return The expected type 30 | */ 31 | @Override 32 | protected Class getExpectedType() { 33 | return Calendar.class; 34 | } 35 | 36 | /** 37 | * Create the Converter with no default value. 38 | * 39 | * @return A new Converter 40 | */ 41 | @Override 42 | protected DateTimeConverter makeConverter() { 43 | return new CalendarConverter(); 44 | } 45 | 46 | /** 47 | * Create the Converter with a default value. 48 | * 49 | * @param defaultValue The default value 50 | * @return A new Converter 51 | */ 52 | @Override 53 | protected CalendarConverter makeConverter(final Calendar defaultValue) { 54 | return new CalendarConverter(defaultValue); 55 | } 56 | 57 | /** 58 | * Convert from a java.util.Date to the Converter's type. 59 | * 60 | * @param value The Date value to convert 61 | * @return The converted value 62 | */ 63 | @Override 64 | protected Calendar toType(final Calendar value) { 65 | return value; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/ClassReloaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.converters; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertFalse; 21 | import static org.junit.jupiter.api.Assertions.assertSame; 22 | import static org.junit.jupiter.api.Assertions.assertTrue; 23 | 24 | import org.junit.jupiter.api.Test; 25 | 26 | /** 27 | * Tests for the ClassReloader utility class. 28 | */ 29 | public class ClassReloaderTest { 30 | 31 | public static class DummyClass { 32 | } 33 | 34 | /** 35 | * Test basic operation of the ClassReloader. 36 | */ 37 | @Test 38 | public void testBasicOperation() throws Exception { 39 | final ClassLoader sharedLoader = this.getClass().getClassLoader(); 40 | final ClassReloader componentLoader = new ClassReloader(sharedLoader); 41 | 42 | final Class sharedClass = DummyClass.class; 43 | final Class componentClass = componentLoader.reload(sharedClass); 44 | 45 | // the two Class objects contain the same bytecode, but are not equal 46 | assertTrue(sharedClass != componentClass); 47 | 48 | // the two class objects have different class loaders 49 | assertSame(sharedLoader, sharedClass.getClassLoader()); 50 | assertSame(componentLoader, componentClass.getClassLoader()); 51 | assertTrue(sharedLoader != componentLoader); 52 | 53 | // verify that objects of these two types are not assignment-compatible 54 | final Object obj1 = sharedClass.newInstance(); 55 | final Object obj2 = componentClass.newInstance(); 56 | 57 | assertTrue(sharedClass.isInstance(obj1), "Obj1 class incorrect"); 58 | assertFalse(componentClass.isInstance(obj1), "Obj1 class incorrect"); 59 | assertFalse(sharedClass.isInstance(obj2), "Obj2 class incorrect"); 60 | assertTrue(componentClass.isInstance(obj2), "Obj2 class incorrect"); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/DateConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.util.Calendar; 20 | import java.util.Date; 21 | 22 | /** 23 | * Test Case for the DateConverter class. 24 | */ 25 | public class DateConverterTest extends AbstractDateConverterTest { 26 | 27 | /** 28 | * Gets the expected type 29 | * 30 | * @return The expected type 31 | */ 32 | @Override 33 | protected Class getExpectedType() { 34 | return Date.class; 35 | } 36 | 37 | /** 38 | * Create the Converter with no default value. 39 | * 40 | * @return A new Converter 41 | */ 42 | @Override 43 | protected DateConverter makeConverter() { 44 | return new DateConverter(); 45 | } 46 | 47 | /** 48 | * Create the Converter with a default value. 49 | * 50 | * @param defaultValue The default value 51 | * @return A new Converter 52 | */ 53 | @Override 54 | protected DateConverter makeConverter(final Date defaultValue) { 55 | return new DateConverter(defaultValue); 56 | } 57 | 58 | /** 59 | * Convert from a Calendar to the appropriate Date type 60 | * 61 | * @param value The Calendar value to convert 62 | * @return The converted value 63 | */ 64 | @Override 65 | protected Date toType(final Calendar value) { 66 | return value.getTime(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/DimensionConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.beanutils2.converters; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertThrows; 23 | 24 | import java.awt.Dimension; 25 | 26 | import org.apache.commons.beanutils2.ConversionException; 27 | import org.junit.jupiter.api.BeforeEach; 28 | import org.junit.jupiter.api.Test; 29 | 30 | /** 31 | * Tests {@link DimensionConverter}. 32 | * 33 | * @since 2.0.0 34 | */ 35 | public class DimensionConverterTest { 36 | 37 | private DimensionConverter converter; 38 | 39 | @BeforeEach 40 | public void before() { 41 | converter = new DimensionConverter(); 42 | } 43 | 44 | @Test 45 | public void testConvertingDimension() { 46 | final Dimension expected = new Dimension(1920, 1080); 47 | final Dimension actual = converter.convert(Dimension.class, "1920x1080"); 48 | 49 | assertEquals(expected, actual); 50 | } 51 | 52 | @Test 53 | public void testConvertingSquare() { 54 | final Dimension expected = new Dimension(512, 512); 55 | final Dimension actual = converter.convert(Dimension.class, "512"); 56 | 57 | assertEquals(expected, actual); 58 | } 59 | 60 | @Test 61 | public void testInvalidDimensions() { 62 | assertThrows(ConversionException.class, () -> converter.convert(Dimension.class, "512n512")); 63 | } 64 | 65 | @Test 66 | public void testInvalidNumberFormatException() { 67 | assertThrows(ConversionException.class, () -> converter.convert(Dimension.class, "3000000000x100")); 68 | } 69 | 70 | @Test 71 | public void testNegativeDimension() { 72 | assertThrows(ConversionException.class, () -> converter.convert(Dimension.class, "-512x512")); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/FileConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.converters; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | import static org.junit.jupiter.api.Assertions.assertThrows; 22 | 23 | import java.io.File; 24 | 25 | import org.apache.commons.beanutils2.ConversionException; 26 | import org.apache.commons.beanutils2.Converter; 27 | import org.junit.jupiter.api.AfterEach; 28 | import org.junit.jupiter.api.BeforeEach; 29 | import org.junit.jupiter.api.Test; 30 | 31 | /** 32 | * Test Case for the FileConverter class. 33 | */ 34 | public class FileConverterTest { 35 | 36 | private Converter converter; 37 | 38 | protected Class getExpectedType() { 39 | return File.class; 40 | } 41 | 42 | protected Converter makeConverter() { 43 | return new FileConverter(); 44 | } 45 | 46 | @BeforeEach 47 | public void setUp() throws Exception { 48 | converter = makeConverter(); 49 | } 50 | 51 | @AfterEach 52 | public void tearDown() throws Exception { 53 | converter = null; 54 | } 55 | 56 | @Test 57 | public void testSimpleConversion() throws Exception { 58 | final String[] message = { "from String", "from String", "from String" }; 59 | 60 | final Object[] input = { "/tmp", "/tmp/foo.txt", "/tmp/does/not/exist.foo" }; 61 | 62 | final File[] expected = { new File("/tmp"), new File("/tmp/foo.txt"), new File("/tmp/does/not/exist.foo") }; 63 | 64 | for (int i = 0; i < expected.length; i++) { 65 | assertEquals(expected[i], converter.convert(File.class, input[i]), message[i] + " to File"); 66 | assertEquals(expected[i], converter.convert(null, input[i]), message[i] + " to null type"); 67 | } 68 | } 69 | 70 | /** 71 | * Tries a conversion to an unsupported target type. 72 | */ 73 | @Test 74 | public void testUnsupportedTargetType() { 75 | assertThrows(ConversionException.class, () -> converter.convert(Integer.class, "/tmp")); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/InetAddressConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.beanutils2.converters; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertThrows; 23 | 24 | import java.net.InetAddress; 25 | import java.net.UnknownHostException; 26 | 27 | import org.apache.commons.beanutils2.ConversionException; 28 | import org.junit.jupiter.api.BeforeEach; 29 | import org.junit.jupiter.api.Test; 30 | 31 | /** 32 | * Tests {@link InetAddressConverter}. 33 | * 34 | * @since 2.0.0 35 | */ 36 | public class InetAddressConverterTest { 37 | 38 | private InetAddressConverter converter; 39 | 40 | @BeforeEach 41 | public void before() { 42 | converter = new InetAddressConverter(); 43 | } 44 | 45 | @Test 46 | public void testConvertingIpv4() throws UnknownHostException { 47 | final InetAddress expected = InetAddress.getByName("192.168.0.1"); 48 | final InetAddress actual = converter.convert(InetAddress.class, "192.168.0.1"); 49 | 50 | assertEquals(expected, actual); 51 | } 52 | 53 | @Test 54 | public void testConvertingIpv6() throws UnknownHostException { 55 | final InetAddress expected = InetAddress.getByName("2001:db8:0:1234:0:567:8:1"); 56 | final InetAddress actual = converter.convert(InetAddress.class, "2001:db8:0:1234:0:567:8:1"); 57 | 58 | assertEquals(expected, actual); 59 | } 60 | 61 | @Test 62 | public void testConvertingLocalhost() throws UnknownHostException { 63 | final InetAddress expected = InetAddress.getByName("127.0.0.1"); 64 | final InetAddress actual = converter.convert(InetAddress.class, "localhost"); 65 | 66 | assertEquals(expected, actual); 67 | } 68 | 69 | @Test 70 | public void testInvalidIp() { 71 | assertThrows(ConversionException.class, () -> converter.convert(InetAddress.class, "512.512.512.512")); 72 | } 73 | 74 | @Test 75 | public void testText() { 76 | assertThrows(ConversionException.class, () -> converter.convert(InetAddress.class, "Hello, world!")); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/LocalDateConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.time.Instant; 20 | import java.time.LocalDate; 21 | import java.time.ZoneId; 22 | import java.util.Calendar; 23 | 24 | /** 25 | * Test Case for the LocalDateConverter class. 26 | */ 27 | public class LocalDateConverterTest extends AbstractDateConverterTest { 28 | 29 | /** 30 | * Gets the expected type 31 | * 32 | * @return The expected type 33 | */ 34 | @Override 35 | protected Class getExpectedType() { 36 | return LocalDate.class; 37 | } 38 | 39 | /** 40 | * Create the Converter with no default value. 41 | * 42 | * @return A new Converter 43 | */ 44 | @Override 45 | protected LocalDateConverter makeConverter() { 46 | return new LocalDateConverter(); 47 | } 48 | 49 | /** 50 | * Create the Converter with a default value. 51 | * 52 | * @param defaultValue The default value 53 | * @return A new Converter 54 | */ 55 | @Override 56 | protected LocalDateConverter makeConverter(final LocalDate defaultValue) { 57 | return new LocalDateConverter(defaultValue); 58 | } 59 | 60 | /** 61 | * Convert from a Calendar to the appropriate Date type 62 | * 63 | * @param value The Calendar value to convert 64 | * @return The converted value 65 | */ 66 | @Override 67 | protected LocalDate toType(final Calendar value) { 68 | return Instant.ofEpochMilli(value.getTimeInMillis()).atZone(ZoneId.systemDefault()).toLocalDate(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/LocalDateTimeConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.time.Instant; 20 | import java.time.LocalDateTime; 21 | import java.time.ZoneId; 22 | import java.util.Calendar; 23 | 24 | /** 25 | * Test Case for the LocalDateTimeConverter class. 26 | */ 27 | public class LocalDateTimeConverterTest extends AbstractDateConverterTest { 28 | 29 | /** 30 | * Gets the expected type 31 | * 32 | * @return The expected type 33 | */ 34 | @Override 35 | protected Class getExpectedType() { 36 | return LocalDateTime.class; 37 | } 38 | 39 | /** 40 | * Create the Converter with no default value. 41 | * 42 | * @return A new Converter 43 | */ 44 | @Override 45 | protected LocalDateTimeConverter makeConverter() { 46 | return new LocalDateTimeConverter(); 47 | } 48 | 49 | /** 50 | * Create the Converter with a default value. 51 | * 52 | * @param defaultValue The default value 53 | * @return A new Converter 54 | */ 55 | @Override 56 | protected LocalDateTimeConverter makeConverter(final LocalDateTime defaultValue) { 57 | return new LocalDateTimeConverter(defaultValue); 58 | } 59 | 60 | /** 61 | * Convert from a Calendar to the appropriate Date type 62 | * 63 | * @param value The Calendar value to convert 64 | * @return The converted value 65 | */ 66 | @Override 67 | protected LocalDateTime toType(final Calendar value) { 68 | return Instant.ofEpochMilli(value.getTimeInMillis()).atZone(ZoneId.systemDefault()).toLocalDateTime(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/LocaleConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.beanutils2.converters; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | import java.util.Locale; 24 | 25 | import org.junit.jupiter.api.BeforeEach; 26 | import org.junit.jupiter.api.Test; 27 | 28 | /** 29 | * Tests {@link LocaleConverter}. 30 | * 31 | * @since 2.0.0 32 | */ 33 | public class LocaleConverterTest { 34 | 35 | private LocaleConverter converter; 36 | 37 | @BeforeEach 38 | public void before() { 39 | converter = new LocaleConverter(); 40 | } 41 | 42 | @Test 43 | public void testConvertCustomLocale() { 44 | final Locale expected = Locale.forLanguageTag("en-owo"); 45 | final Locale actual = converter.convert(Locale.class, "en-owo"); 46 | 47 | assertEquals(expected, actual); 48 | } 49 | 50 | @Test 51 | public void testConvertStandardLocale() { 52 | final Locale expected = Locale.ENGLISH; 53 | final Locale actual = converter.convert(Locale.class, "en"); 54 | 55 | assertEquals(expected, actual); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.time.Instant; 20 | import java.time.OffsetDateTime; 21 | import java.time.ZoneId; 22 | import java.util.Calendar; 23 | 24 | /** 25 | * Test Case for the OffsetDateTimeConverter class. 26 | */ 27 | public class OffsetDateTimeConverterTest extends AbstractDateConverterTest { 28 | 29 | /** 30 | * Gets the expected type 31 | * 32 | * @return The expected type 33 | */ 34 | @Override 35 | protected Class getExpectedType() { 36 | return OffsetDateTime.class; 37 | } 38 | 39 | /** 40 | * Create the Converter with no default value. 41 | * 42 | * @return A new Converter 43 | */ 44 | @Override 45 | protected OffsetDateTimeConverter makeConverter() { 46 | return new OffsetDateTimeConverter(); 47 | } 48 | 49 | /** 50 | * Create the Converter with a default value. 51 | * 52 | * @param defaultValue The default value 53 | * @return A new Converter 54 | */ 55 | @Override 56 | protected OffsetDateTimeConverter makeConverter(final OffsetDateTime defaultValue) { 57 | return new OffsetDateTimeConverter(defaultValue); 58 | } 59 | 60 | /** 61 | * Convert from a Calendar to the appropriate Date type 62 | * 63 | * @param value The Calendar value to convert 64 | * @return The converted value 65 | */ 66 | @Override 67 | protected OffsetDateTime toType(final Calendar value) { 68 | return OffsetDateTime.ofInstant(Instant.ofEpochMilli(value.getTimeInMillis()), ZoneId.systemDefault()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/PatternConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.beanutils2.converters; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | import java.util.regex.Pattern; 24 | 25 | import org.junit.jupiter.api.BeforeEach; 26 | import org.junit.jupiter.api.Test; 27 | 28 | /** 29 | * Tests {@link PatternConverter}. 30 | * 31 | * @since 2.0.0 32 | */ 33 | public class PatternConverterTest { 34 | 35 | private PatternConverter converter; 36 | 37 | @BeforeEach 38 | public void before() { 39 | converter = new PatternConverter(); 40 | } 41 | 42 | @Test 43 | public void testConvertingPattern() { 44 | final String expected = "(?i)Ow.+O"; 45 | final String actual = converter.convert(Pattern.class, "(?i)Ow.+O").toString(); 46 | 47 | assertEquals(expected, actual); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/PointConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.beanutils2.converters; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | import java.awt.Point; 24 | 25 | import org.junit.jupiter.api.BeforeEach; 26 | import org.junit.jupiter.api.Test; 27 | 28 | /** 29 | * Tests {@link PointConverter}. 30 | * 31 | * @since 2.0.0 32 | */ 33 | public class PointConverterTest { 34 | 35 | private PointConverter converter; 36 | 37 | @BeforeEach 38 | public void before() { 39 | converter = new PointConverter(); 40 | } 41 | 42 | @Test 43 | public void testConvertingNoSpace() { 44 | final Point expected = new Point(100, 200); 45 | final Point actual = converter.convert(Point.class, "(100,200)"); 46 | 47 | assertEquals(expected, actual); 48 | } 49 | 50 | @Test 51 | public void testConvertingPoint() { 52 | final Point expected = new Point(100, 200); 53 | final Point actual = converter.convert(Point.class, "(100, 200)"); 54 | 55 | assertEquals(expected, actual); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/StringConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.junit.jupiter.api.BeforeEach; 22 | import org.junit.jupiter.api.Test; 23 | 24 | /** 25 | * Test case for {@code StringConverter}. 26 | */ 27 | public class StringConverterTest { 28 | /** The converter to be tested. */ 29 | private StringConverter converter; 30 | 31 | @BeforeEach 32 | protected void setUp() throws Exception { 33 | converter = new StringConverter(); 34 | } 35 | 36 | /** 37 | * Tests a conversion to a string type. 38 | */ 39 | @Test 40 | public void testConvertToTypeString() { 41 | final Object value = new Object(); 42 | final String strVal = converter.convert(String.class, value); 43 | assertEquals(value.toString(), strVal, "Wrong conversion result"); 44 | } 45 | 46 | /** 47 | * Tests whether the correct default type is returned. 48 | */ 49 | @Test 50 | public void testDefaultType() { 51 | assertEquals(String.class, converter.getDefaultType(), "Wrong default type"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/URLConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.converters; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | import java.net.URL; 23 | 24 | import org.junit.jupiter.api.BeforeEach; 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Test Case for the URLConverter class. 29 | */ 30 | public class URLConverterTest { 31 | 32 | private URLConverter converter; 33 | 34 | @BeforeEach 35 | public void before() { 36 | converter = new URLConverter(); 37 | } 38 | 39 | @Test 40 | public void testSimpleConversion() { 41 | final String[] input = { "http://www.apache.org", "http://www.apache.org/", "ftp://cvs.apache.org", "file://project.xml", "http://208.185.179.12", 42 | "http://www.apache.org:9999/test/thing", "http://user:admin@www.apache.org:50/one/two.three", "http://notreal.apache.org", 43 | "http://notreal.apache.org/test/file.xml#计算机图形学", 44 | "http://notreal.apache.org/test/file.xml#%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9B%BE%E5%BD%A2%E5%AD%A6" }; 45 | 46 | for (final String urlString : input) { 47 | assertEquals(urlString, converter.convert(URL.class, urlString).toString(), "from String to URL"); 48 | assertEquals(urlString, converter.convert(null, urlString).toString(), "from String to null type"); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/converters/ZonedDateTimeConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.converters; 18 | 19 | import java.time.Instant; 20 | import java.time.ZoneId; 21 | import java.time.ZonedDateTime; 22 | import java.util.Calendar; 23 | 24 | /** 25 | * Test Case for the ZonedDateTimeConverter class. 26 | */ 27 | public class ZonedDateTimeConverterTest extends AbstractDateConverterTest { 28 | 29 | /** 30 | * Gets the expected type 31 | * 32 | * @return The expected type 33 | */ 34 | @Override 35 | protected Class getExpectedType() { 36 | return ZonedDateTime.class; 37 | } 38 | 39 | /** 40 | * Create the Converter with no default value. 41 | * 42 | * @return A new Converter 43 | */ 44 | @Override 45 | protected ZonedDateTimeConverter makeConverter() { 46 | return new ZonedDateTimeConverter(); 47 | } 48 | 49 | /** 50 | * Create the Converter with a default value. 51 | * 52 | * @param defaultValue The default value 53 | * @return A new Converter 54 | */ 55 | @Override 56 | protected ZonedDateTimeConverter makeConverter(final ZonedDateTime defaultValue) { 57 | return new ZonedDateTimeConverter(defaultValue); 58 | } 59 | 60 | /** 61 | * Convert from a Calendar to the appropriate Date type 62 | * 63 | * @param value The Calendar value to convert 64 | * @return The converted value 65 | */ 66 | @Override 67 | protected ZonedDateTime toType(final Calendar value) { 68 | return ZonedDateTime.ofInstant(Instant.ofEpochMilli(value.getTimeInMillis()), ZoneId.systemDefault()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/locale/LocaleBeanUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.locale; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.apache.commons.beanutils2.TestBean; 22 | import org.apache.commons.logging.Log; 23 | import org.apache.commons.logging.LogFactory; 24 | import org.junit.jupiter.api.Test; 25 | 26 | /** 27 | * Test Case for {@link LocaleBeanUtils}. 28 | */ 29 | public class LocaleBeanUtilsTest { 30 | 31 | private static final Log LOG = LogFactory.getLog(LocaleBeanUtilsTest.class); 32 | 33 | /** 34 | * Test setting a nested indexed property 35 | */ 36 | @Test 37 | public void testSetNestedPropertyIndexed() throws Exception { 38 | final TestBean bean = new TestBean(); 39 | bean.getNested().setIntIndexed(1, 51); 40 | assertEquals(51, bean.getNested().getIntIndexed(1), "Initial value[1] 51"); 41 | LocaleBeanUtils.setProperty(bean, "nested.intIndexed[1]", "123", null); 42 | assertEquals(123, bean.getNested().getIntIndexed(1), "Check Set Value"); 43 | } 44 | 45 | /** 46 | * Test setting a nested simple property 47 | */ 48 | @Test 49 | public void testSetNestedPropertySimple() throws Exception { 50 | final TestBean bean = new TestBean(); 51 | bean.getNested().setIntProperty(5); 52 | assertEquals(5, bean.getNested().getIntProperty(), "Initial value 5"); 53 | LocaleBeanUtils.setProperty(bean, "nested.intProperty", "123", null); 54 | assertEquals(123, bean.getNested().getIntProperty(), "Check Set Value"); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/memoryleaktests/pojotests/CustomInteger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.memoryleaktests.pojotests; 18 | 19 | /** 20 | * Custom number implementation to test with converters. 21 | */ 22 | public class CustomInteger extends Number { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | private final int i; 27 | 28 | /** 29 | * Constructs a new instance. 30 | */ 31 | public CustomInteger() { 32 | this.i = 12345; 33 | } 34 | 35 | /** 36 | * Constructs a new instance. 37 | * 38 | * @param i the integer value 39 | */ 40 | public CustomInteger(final int i) { 41 | this.i = i; 42 | } 43 | 44 | /** 45 | * Gets the double value. 46 | * 47 | * @return the double value 48 | */ 49 | @Override 50 | public double doubleValue() { 51 | return i; 52 | } 53 | 54 | /** 55 | * Gets the float value. 56 | * 57 | * @return the float value 58 | */ 59 | @Override 60 | public float floatValue() { 61 | return i; 62 | } 63 | 64 | /** 65 | * Gets the integer value. 66 | * 67 | * @return the integer value 68 | */ 69 | @Override 70 | public int intValue() { 71 | return i; 72 | } 73 | 74 | /** 75 | * Gets the long value. 76 | * 77 | * @return the long value 78 | */ 79 | @Override 80 | public long longValue() { 81 | return i; 82 | } 83 | 84 | /** 85 | * Gets a String representation of this number. 86 | */ 87 | @Override 88 | public String toString() { 89 | return Integer.toString(i); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/memoryleaktests/pojotests/SomeMappedPojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.memoryleaktests.pojotests; 18 | 19 | import java.util.HashMap; 20 | 21 | /** 22 | * Test POJO with mapped property 23 | */ 24 | public class SomeMappedPojo { 25 | 26 | private HashMap mappedProperty; 27 | 28 | public String getMappedProperty(final String key) { 29 | // Create the map the very first time 30 | if (mappedProperty == null) { 31 | mappedProperty = new HashMap<>(); 32 | mappedProperty.put("First Key", "First Value"); 33 | mappedProperty.put("Second Key", "Second Value"); 34 | } 35 | return mappedProperty.get(key); 36 | } 37 | 38 | public void setMappedProperty(final String key, final String value) { 39 | // Create the map the very first time 40 | if (mappedProperty == null) { 41 | mappedProperty = new HashMap<>(); 42 | mappedProperty.put("First Key", "First Value"); 43 | mappedProperty.put("Second Key", "Second Value"); 44 | } 45 | mappedProperty.put(key, value); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/memoryleaktests/pojotests/SomePojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.beanutils2.memoryleaktests.pojotests; 18 | 19 | /** 20 | * Test POJO 21 | */ 22 | public class SomePojo { 23 | 24 | String name = "initialValue"; 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(final String name) { 31 | this.name = name; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/priv/PackageBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.priv; 19 | 20 | /** 21 | *

22 | * This class is designed to test the default access JVM problem workaround. The issue is that public methods of a public subclass contained in a default access 23 | * superclass are returned by reflection but an IllegalAccessException is thrown when they are invoked. 24 | *

25 | *

26 | * This is the default access superclass 27 | *

28 | */ 29 | class PackageBean { 30 | 31 | /** 32 | */ 33 | private String bar = "This is bar"; 34 | 35 | /** 36 | * Package private constructor - can only use factory method to create beans. 37 | */ 38 | PackageBean() { 39 | 40 | } 41 | 42 | public String getBar() { 43 | 44 | return this.bar; 45 | 46 | } 47 | 48 | public void setBar(final String bar) { 49 | 50 | this.bar = bar; 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/priv/PrivateBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.priv; 19 | 20 | /** 21 | * Bean that has a private constructor that exposes properties via various mechanisms (based on property name): 22 | *
    23 | *
  • foo - Via direct public method 24 | *
  • bar - Via directly implemented interface 25 | *
  • baz - Via indirectly implemented interface 26 | *
27 | */ 28 | class PrivateBean implements PrivateDirect { 29 | 30 | /** 31 | * A directly implemented property. 32 | */ 33 | private final String foo = "This is foo"; 34 | 35 | /** 36 | * A property accessible via a directly implemented interface. 37 | */ 38 | private final String bar = "This is bar"; 39 | 40 | /** 41 | * A property accessible via an indirectly implemented interface. 42 | */ 43 | private final String baz = "This is baz"; 44 | 45 | /** 46 | * Package private constructor - can only use factory method to create beans. 47 | */ 48 | PrivateBean() { 49 | 50 | } 51 | 52 | @Override 53 | public String getBar() { 54 | 55 | return this.bar; 56 | 57 | } 58 | 59 | @Override 60 | public String getBaz() { 61 | 62 | return this.baz; 63 | 64 | } 65 | 66 | public String getFoo() { 67 | 68 | return this.foo; 69 | 70 | } 71 | 72 | /** 73 | * A method accessible via a directly implemented interface. 74 | */ 75 | @Override 76 | public String methodBar(final String in) { 77 | 78 | return in; 79 | 80 | } 81 | 82 | /** 83 | * A method accessible via an indirectly implemented interface. 84 | */ 85 | @Override 86 | public String methodBaz(final String in) { 87 | 88 | return in; 89 | 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/priv/PrivateBeanFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.priv; 19 | 20 | /** 21 | * Factory class for PrivateBean instances. 22 | */ 23 | 24 | public class PrivateBeanFactory { 25 | 26 | /** 27 | * Factory method to create new beans. 28 | */ 29 | public static PrivateDirect create() { 30 | 31 | return new PrivateBean(); 32 | 33 | } 34 | 35 | /** 36 | * Factory method to create new beans. 37 | */ 38 | public static PrivateDirect createSubclass() { 39 | 40 | return new PrivateBeanSubclass(); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/priv/PrivateBeanSubclass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.priv; 19 | 20 | /** 21 | * Bean that exposes methods defined by an interface that is implemented in the superclass. 22 | */ 23 | 24 | final class PrivateBeanSubclass extends PrivateBean { 25 | 26 | /** 27 | * Create a new PrivateBeanSubclass instance. 28 | */ 29 | PrivateBeanSubclass() { 30 | 31 | } 32 | 33 | /** 34 | * A property accessible via the superclass. 35 | */ 36 | @Override 37 | public String getBar() { 38 | 39 | return super.getBar(); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/priv/PrivateDirect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.priv; 19 | 20 | /** 21 | * Interface that is directly implemented by PrivateBean. 22 | */ 23 | 24 | public interface PrivateDirect extends PrivateIndirect { 25 | 26 | /** 27 | * A property accessible via a directly implemented interface. 28 | */ 29 | String getBar(); 30 | 31 | /** 32 | * A method accessible via a directly implemented interface. 33 | */ 34 | String methodBar(String in); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/priv/PrivateIndirect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.priv; 19 | 20 | /** 21 | * Interface that is indirectly implemented by PrivateBean. 22 | */ 23 | 24 | public interface PrivateIndirect { 25 | 26 | /** 27 | * A property accessible via an indirectly implemented interface. 28 | */ 29 | String getBaz(); 30 | 31 | /** 32 | * A method accessible via an indirectly implemented interface. 33 | */ 34 | String methodBaz(String in); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/beanutils2/priv/PublicSubBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.beanutils2.priv; 19 | 20 | /** 21 | *

22 | * This class is designed to test the default access JVM problem workaround. The issue is that public methods of a public subclass contained in a default access 23 | * superclass are returned by reflection but an IllegalAccessException is thrown when they are invoked. 24 | *

25 | * 26 | *

27 | * This is the default access superclass 28 | *

29 | */ 30 | 31 | public class PublicSubBean extends PackageBean { 32 | 33 | /** 34 | * A directly implemented property. 35 | */ 36 | private String foo = "This is foo"; 37 | 38 | /** 39 | * Package private constructor - can only use factory method to create beans. 40 | */ 41 | public PublicSubBean() { 42 | 43 | } 44 | 45 | public String getFoo() { 46 | 47 | return this.foo; 48 | 49 | } 50 | 51 | public void setFoo(final String foo) { 52 | 53 | this.foo = foo; 54 | 55 | } 56 | } 57 | --------------------------------------------------------------------------------