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

Fix control flow error and use catch-syntax for instance checking #101

Merged

Conversation

cobratbq
Copy link
Contributor

@cobratbq cobratbq commented May 11, 2020

Fix error in control flow logic for handling the PGPKeyNotFound exception and use the catch-syntax for doing the instance-test for PGPKeyNotFound exception + dedicated exception message.

The control flow error is that PGPKeyNotFound is derived from IOException instead of embedded as a root cause.

Stack trace produced in case of PGPKeyNotFound exception:

[ERROR] Failed to execute goal org.simplify4u.plugins:pgpverify-maven-plugin:1.8.0-SNAPSHOT:check (default-cli) on project otr4j: Failed to process signature '/var/home/user/.m2/repository/com/github/spotbugs/spotbugs/4.0.2/spotbugs-4.0.2.jar.asc' for artifact com.github.spotbugs:spotbugs:jar:4.0.2: PGP server returned an error: HTTP/1.1 404 Not Found for: https://keyserver.ubuntu.com/pks/lookup?op=get&options=mr&search=0xA5DEF5A76F94A471 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.simplify4u.plugins:pgpverify-maven-plugin:1.8.0-SNAPSHOT:check (default-cli) on project otr4j: Failed to process signature '/var/home/user/.m2/repository/com/github/spotbugs/spotbugs/4.0.2/spotbugs-4.0.2.jar.asc' for artifact com.github.spotbugs:spotbugs:jar:4.0.2
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoFailureException: Failed to process signature '/var/home/user/.m2/repository/com/github/spotbugs/spotbugs/4.0.2/spotbugs-4.0.2.jar.asc' for artifact com.github.spotbugs:spotbugs:jar:4.0.2
    at org.simplify4u.plugins.PGPVerifyMojo.verifyPGPSignature (PGPVerifyMojo.java:482)
    at org.simplify4u.plugins.PGPVerifyMojo.verifyArtifactSignatures (PGPVerifyMojo.java:402)
    at org.simplify4u.plugins.PGPVerifyMojo.execute (PGPVerifyMojo.java:315)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.simplify4u.plugins.keyserver.PGPKeyNotFound: PGP server returned an error: HTTP/1.1 404 Not Found for: https://keyserver.ubuntu.com/pks/lookup?op=get&options=mr&search=0xA5DEF5A76F94A471
    at org.simplify4u.plugins.keyserver.PGPKeysServerClient.copyKeyToOutputStream (PGPKeysServerClient.java:244)
    at org.simplify4u.plugins.keyserver.PGPKeysCache.receiveKey (PGPKeysCache.java:176)
    at org.simplify4u.plugins.keyserver.PGPKeysCache.lambda$getKeyRing$1 (PGPKeysCache.java:140)
    at org.simplify4u.plugins.keyserver.PGPKeysCache$KeyServerListOne.execute (PGPKeysCache.java:281)
    at org.simplify4u.plugins.keyserver.PGPKeysCache.getKeyRing (PGPKeysCache.java:140)
    at org.simplify4u.plugins.PGPVerifyMojo.verifyPGPSignature (PGPVerifyMojo.java:451)
    at org.simplify4u.plugins.PGPVerifyMojo.verifyArtifactSignatures (PGPVerifyMojo.java:402)
    at org.simplify4u.plugins.PGPVerifyMojo.execute (PGPVerifyMojo.java:315)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

@cobratbq cobratbq requested a review from slawekjaranowski May 11, 2020 15:25
@cobratbq cobratbq changed the title Use catch-syntax capabilities for instance checking. Fix control flow error and use catch-syntax for instance checking May 11, 2020
Copy link
Member

@slawekjaranowski slawekjaranowski left a comment

Choose a reason for hiding this comment

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

Please try to add some IT test

@cobratbq cobratbq self-assigned this May 13, 2020
The control flow logic for the 'noKey' specifier is broken as it matches
on the wrong exception to identify the case. This is fixed and while
fixing starts using Java's catch-syntax capabilities for implicitly
performing the instance-of test.

Added IT tests 'noKeyOK' and 'noKeyFail' for verifying correct behavior.
Both tests use a PGP keypair that was never published. The 'helloworld'
artifact is installed in the local repo used for IT tests only.

Slightly modified capitalization in the exception's error message
because of my OCD.
@cobratbq cobratbq force-pushed the use-catch-syntax-for-typecheck branch from b6636ad to c61ee0f Compare May 15, 2020 17:56
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

75.0% 75.0% Coverage
0.0% 0.0% Duplication

@cobratbq cobratbq requested a review from slawekjaranowski May 15, 2020 18:13
@slawekjaranowski slawekjaranowski added this to the v1.8.0 milestone May 15, 2020
@slawekjaranowski slawekjaranowski merged commit e12cc0b into s4u:master May 15, 2020
@cobratbq cobratbq deleted the use-catch-syntax-for-typecheck branch May 17, 2020 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants