Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid NullPointerException when customChange has no "class" attribute #1648

Conversation

danielthegray
Copy link
Contributor

@danielthegray danielthegray commented Jan 22, 2021

Environment

Liquibase Version: all

Liquibase Integration & Version: all

Liquibase Extension(s) & Version: all

Database Vendor & Version: all

Operating System Type & Version: all

Pull Request Type

  • Bug fix (non-breaking change which fixes an issue.)
  • Enhancement/New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

If a customChange node is missing the "class" attribute (either by typo, or mis-indentation) a NullPointerException is thrown:

Caused by: java.lang.NullPointerException
    at java.lang.Class.forName0(Native Method) ~[?:?]
    at java.lang.Class.forName(Class.java:398) ~[?:?]
    at liquibase.change.custom.CustomChangeWrapper.customLoadLogic(CustomChangeWrapper.java:335) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?]
    at liquibase.change.AbstractChange.load(AbstractChange.java:719) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?]
    at liquibase.change.custom.CustomChangeWrapper.load(CustomChangeWrapper.java:312) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?]
    at liquibase.changelog.ChangeSet.toChange(ChangeSet.java:480) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?]
    at liquibase.changelog.ChangeSet.handleChildNode(ChangeSet.java:413) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?]   
    at liquibase.changelog.ChangeSet.handleChildNode(ChangeSet.java:409) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?]   
    at liquibase.changelog.ChangeSet.load(ChangeSet.java:337) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?]
    at liquibase.changelog.DatabaseChangeLog.createChangeSet(DatabaseChangeLog.java:606) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?]
    at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:336) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?]
    at liquibase.changelog.DatabaseChangeLog.load(DatabaseChangeLog.java:305) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?] 
    at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:77) ~[usafe-cli-1.0.1-SNAPSHOT-all.jar:?]

Steps To Reproduce

Create a customChange node with no class attribute, and you will see this exception.

Actual Behavior

Check description.

Expected/Desired Behavior

A nicer exception should appear with a better error message.

Fast Track PR Acceptance Checklist:

Need Help?

Come chat with us on our discord channel


Dev Handoff Notes (Internal Use)

Links

Testing

  • Steps to Reproduce: See above (use yaml format)
  • Guidance:
    • Impact: Just adds a check for a missing argument

Dev Verification

Code review and ensured new automated test is good

Manual Tests

Verify update shows correct error message when class attribute is not specified.

  • create a changelog with customChange changeset, but do not specify class attribute

  • liquibase --log-level INFO update --changelog-file changelog.yaml

  • Custom change node has no 'class' attribute! error message is shown

Verify update is successful when class attribute is specified.

  • specify 'class' attribute in your changelog

  • liquibase update --changelog-file changelog.yaml

  • update is successful

┆Issue is synchronized with this Jira Bug by Unito

@danielthegray danielthegray force-pushed the improve-missing-class-name-custom-change-error branch from 90f64ad to c95798b Compare January 22, 2021 10:09
@molivasdat
Copy link
Contributor

Thanks @danielthegray for fixing this issue. Always appreciated when our core team helps fix issues.

@danielthegray danielthegray force-pushed the improve-missing-class-name-custom-change-error branch from a030f39 to 77ec354 Compare May 6, 2021 16:54
@danielthegray danielthegray changed the base branch from 3.10.x to master May 6, 2021 16:54
@danielthegray danielthegray changed the base branch from master to 4.4.x August 6, 2021 16:44
@kataggart kataggart added this to To Do in Conditioning++ via automation Dec 27, 2021
…s://github.com/danielthegray/liquibase into danielthegray-improve-missing-class-name-custom-change-error

# Conflicts:
#	liquibase-core/src/test/groovy/liquibase/change/custom/CustomChangeWrapperTest.groovy
@nvoxland nvoxland changed the base branch from 4.4.x to master January 5, 2022 21:38
Copy link
Contributor

@nvoxland nvoxland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good, thanks!

@liquibase liquibase deleted a comment from codecov-commenter Jan 5, 2022
@liquibase liquibase deleted a comment from codecov bot Jan 5, 2022
@nvoxland nvoxland moved this from To Do to Code Review in Conditioning++ Jan 5, 2022
@suryaaki2 suryaaki2 moved this from Code Review to Ready for Handoff (In JIRA) in Conditioning++ Jan 6, 2022
@nvoxland nvoxland added the SafeToBuild Indicates that a particular PR contains changes which are safe to build using GitHub actions label Feb 9, 2022
@yodzhubeiskyi
Copy link
Contributor

yodzhubeiskyi commented Feb 10, 2022

Verify update shows correct error message when class attribute is not specified. PASS

Unexpected error running Liquibase: Error parsing changelog.yaml

liquibase.exception.CommandExecutionException: liquibase.exception.LiquibaseException: Unexpected error running Liquibase: Custom change node has no 'class' attribute!

Verify update is successful when class attribute is specified. PASS

Liquibase version [Core: //improve-missing-class-name-custom-change-error/1452/fc0771/2022-02-09 21:38+0000, Pro: master/591/f653ec/2022-02-09T18:09:13Z] #1452

@nvoxland nvoxland merged commit c6ed3fe into liquibase:master Feb 14, 2022
Conditioning++ automation moved this from Ready for Handoff (In JIRA) to Done Feb 14, 2022
@danielthegray danielthegray deleted the improve-missing-class-name-custom-change-error branch February 14, 2022 21:21
@nvoxland nvoxland added this to the v4.8.0 milestone Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DBAll ImpactLow IntegrationAny SafeToBuild Indicates that a particular PR contains changes which are safe to build using GitHub actions Severity3 SyncTicket TypeEnhancement
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants