Java bytecode static analyzer

Overview

This project is abandoned and unlikely will be supported in future

HuntBugs 0.0.11

Join the chat at https://gitter.im/amaembo/huntbugs Maven Central Build Status Coverage Status

New Java bytecode static analyzer tool based on Procyon Compiler Tools aimed to supersede the FindBugs. Currently in early development stage, though already could be tried.

Currently 222 FindBugs warnings reimplemented and several new warnings added.

Use with Maven

Compile project and run mvn one.util:huntbugs-maven-plugin:huntbugs

The output report is located in target/huntbugs/report.html

Use with Ant

  • Build huntbugs-ant-plugin via mvn package (or alternatively download from here)
  • Take the resulting huntbugs-ant-plugin-<version>-nodeps.jar
  • Define the task:
<taskdef resource="one/util/huntbugs/ant/antlib.xml">
    <classpath path="path/to/huntbugs-ant-plugin-<version>-nodeps.jar"/>
</taskdef>
  • Run it:
<huntbugs classPath="${MY_APP_CLASSPATH}" 
          auxClassPath="${DEPS_CLASSPATH}" 
          html="path/to/html/report.html" 
          xml="path/to/xml/report.xml"/>

Use with Gradle

Check the Gradle plugin page

Use with Eclipse

Check the Eclipse plugin page (in early development stage)

Exec as command-line tool

Command-line tool is mostly aimed to aid developers. Nevertheless you may use it if you like. To launch use mvn exec:java -Dexec.args="...args..." inside huntbugs subdirectory. Examples:

  • mvn exec:java -Dexec.args="-lw" will list all the warnings.
  • mvn exec:java -Dexec.args="myfolder/*.jar" will analyze all jars inside myfolder writing the report into huntbugs.warnings.xml and huntbugs.warnings.html in current directory.
  • mvn exec:java will show all the supported command line options.
Comments
  • Custom detectors demo

    Custom detectors demo

    This PR is based on (and contains) https://github.com/amaembo/huntbugs/pull/16 to demonstrate development of custom detector and their usage in sample project:

    • multiple messages.xml are read and merged
    • Java SPI mechanism for discovering 3-rd party detectors
    • default detector package is still needs to be used
    • huntbugs maven plugin is not affected (to configure it standard tag 'dependencies' inside tag 'plugin' could be used)
    • removed redundant public modifiers at interface nested classes (public by default)
    • plugin currently supports single package for detectors
    • introducing helper class to test detectors (to be reused)
    • custom detectors can be located in custom packages
    • minor refactoring
    • added license agreement headers
    • demonstrating development of custom detector
    • sample project for custom detectors
    • detectors are automatically tested with sample code in test scope
    • sample project with HuntBugs maven plugin with custom detectors
    • production code in sample project is not annotated with @AssertWarning
    • sample project might be used for demonstration of project configuration without custom detectors as well
    opened by volkovs 10
  • Supporting 3-rd party detectors (rules)

    Supporting 3-rd party detectors (rules)

    We would like to write our own project specific rules. So, this is currently a working solution for Maven. I didn't tested Ant or Gradle, but should be as simple as adding your artifact (with custom detectors) to (HuntBugs plugin) classpath.

    • multiple messages.xml are read and merged
    • Java SPI mechanism for discovering 3-rd party detectors
    • default detector package is still needs to be used
    • huntbugs maven plugin is not affected (to configure it standard tag 'dependencies' inside tag 'plugin' could be used)
    • removed redundant public modifiers at interface nested classes (public by default)

    What do you think?

    opened by volkovs 4
  • Supporting pom type and transitive dependencies (#17)

    Supporting pom type and transitive dependencies (#17)

    • traversing dependencies tree
    • collecting compile time dependencies
    • understanding POM type dependencies
    • understanding other transitive dependencies
    • understanding excluded transitive dependencies
    • new dependency org.apache.maven.shared:maven-dependency-tree is required
    • @Component annotation is used for Mojo injection (since May, 2012)
    opened by volkovs 3
  • FP: Local variable is assigned to a value which is never used

    FP: Local variable is assigned to a value which is never used

    This code assigns a new value to the local variable field and this value is never
    used subsequently. Probably something else was meant or the assignment could be removed.
    

    This one is odd because the field is used in the happy path.

    Field field = null;
    try {
      // try OpenJDK field name
      field = Unsafe.class.getDeclaredField(openJdk);
    } catch (NoSuchFieldException e) {
      try {
        // try Android field name...
      } catch (NoSuchFieldException e2) {
        // try to create a new instance...
      }
      field.setAccessible(true);
      return (Unsafe) field.get(null);
    }
    reply-needed 
    opened by ben-manes 2
  • Mojo: type defined in pom.xml dependency (of pom type) is not resolved

    Mojo: type defined in pom.xml dependency (of pom type) is not resolved

    If in pom.xml you have dependency of pom type, then those types are not resolved. I.e. TypeDefinition td = typeReference.resolve(); // td = null;

    (Replacing pom type dependency to regular jar dependency solves the issue)

    opened by volkovs 2
  • can not run huntbugs

    can not run huntbugs "java.lang.NullPointerException"

    I hit into problem when I am trying to run huntbugs

    sergei-rudenkov@EPBYMINW4306:~/IdeaProjects/spring_training/theatre_service$ mvn -e one.util:huntbugs-maven-plugin:huntbugs
    + Error stacktraces are turned on.
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Spring Core Hometask Skeleton
    [INFO]    task-segment: [one.util:huntbugs-maven-plugin:huntbugs]
    [INFO] ------------------------------------------------------------------------
    [INFO] [huntbugs:huntbugs {execution: default-cli}]
    [INFO] HuntBugs: +dir /home/sergei-rudenkov/IdeaProjects/spring_training/theatre_service/target/classes
    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] Failed to run HuntBugs
    
    [INFO] ------------------------------------------------------------------------
    [INFO] Trace
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to run HuntBugs
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
    Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to run HuntBugs
        at one.util.huntbugs.maven.plugin.HuntBugsMojo.execute(HuntBugsMojo.java:100)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        ... 17 more
    Caused by: java.lang.NullPointerException
        at one.util.huntbugs.maven.plugin.HuntBugsMojo.constructRepository(HuntBugsMojo.java:114)
        at one.util.huntbugs.maven.plugin.HuntBugsMojo.execute(HuntBugsMojo.java:91)
        ... 19 more
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: < 1 second
    [INFO] Finished at: Fri May 27 17:59:45 MSK 2016
    [INFO] Final Memory: 8M/150M
    [INFO] ------------------------------------------------------------------------
    
    

    Could you please point me out what is can be wrong with my project?

    opened by Sergei-Rudenkov 2
  • FP: Useless void method

    FP: Useless void method

    The method SingleConsumerQueue.LinearizableNode.await() seems to do nothing useful.
    Analysis discovers that void method SingleConsumerQueue.LinearizableNode.await() has non-trivial body, yet does nothing useful. Probably there's some mistake.
    

    This is a spin loop watching a volatile field. This would be true if the field was non-volatile, as the JVM could optimize it away as dead code. The volatile introduces a load barrier so that the signal is observed.

    volatile boolean done;
    
    void await() {
      while (!done) {}
    }
    
    bug 
    opened by ben-manes 1
  • Question: is there any plan to release newer version?

    Question: is there any plan to release newer version?

    Hi,

    We use pom dependencies and need the fix "HuntBugsMojo: art.getType() checked" to be released.

    Do you think you could release current version 0.0.10 (before 0.1.0 which might take more time) in observable future? :)

    opened by volkovs 1
  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    amaembo/huntbugs now has a Chat Room on Gitter

    @amaembo has just created a chat room. You can visit it here: https://gitter.im/amaembo/huntbugs.

    This pull-request adds this badge to your README.md:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

    opened by gitter-badger 1
  • Bump ant from 1.7.1 to 1.9.15 in /huntbugs-ant-plugin

    Bump ant from 1.7.1 to 1.9.15 in /huntbugs-ant-plugin

    Bumps ant from 1.7.1 to 1.9.15.

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • TeamCity integration

    TeamCity integration

    Hi! It is possible to implement TeamCity integration for HuntBugs? May be I could contribute this feature if I will get initial explanation where to start.

    opened by akuznetsov-gridgain 1
  • Add $deserializeLambda$ to a set of known serialization-related methods

    Add $deserializeLambda$ to a set of known serialization-related methods

    Fixes #31

    I'm not sure how to add a test. I tried to add

        @AssertNoWarning("UncalledPrivateMethod")
        private static class SerializedClass implements Serializable {
            private int foo;
    
            private Runnable foo() {
                return () -> {
                    System.out.println(foo);
                };
            }
        }
    

    but that's passing even without the patch. I guess I'd need to annotate the $deserializeLambda$ method, but the method is generated by Java compiler.

    opened by jerrinot 2
  • FP: Private method is never called

    FP: Private method is never called

    The method CaffeineConfiguration.$deserializeLambda$() is private and never called.
    The private method CaffeineConfiguration.$deserializeLambda$() is never explicitly called
    and probably should be removed. If it's designed to be called via reflection or via method
    handles API, it's a good practice to annotate it by some annotation which will explicitly
    signal that the method is necessary.
    

    Seems to not recognize Java serialization yet. Unfortunately required due to the JSR's interface.

    opened by ben-manes 0
  • FP: Unsupported method call (2)

    FP: Unsupported method call (2)

    The Map.put() is unsupported.
    This code calls Map.put(). However analysis found that this method as well as 
    and its overrides (if applicable) unconditionally throw UnsupportedOperationException,
    so it's likely that this call will fail.
    

    This makes little sense to me as it is calling into a HashMap. It must be observing that AbstractMap#put() throws an UOE but the subclass does not.

    Map<K, V> result = new HashMap<>(loaded.size());
    loaded.forEach((key, value) -> {
      if ((key == null) || (value == null)) {
        nullBulkLoad.set(true);
      } else {
        result.put(key, value);
      }
    });
    
    opened by ben-manes 1
Releases(huntbugs-all-0.0.11)
  • huntbugs-all-0.0.11(Sep 24, 2016)

    Release Notes for 0.0.11:

    Maven: supporting transitive dependencies (including dependency of pom type)
    Plugin mechanism to support 3-rd party detectors
    Sample project to demonstrate development of custom detectors
    Sample project configured to use HuntBugs
    
    Source code(tar.gz)
    Source code(zip)
Owner
Tagir Valeev
Tagir Valeev
:coffee: SonarSource Static Analyzer for Java Code Quality and Security

Code Quality and Security for Java This SonarSource project is a code analyzer for Java projects. Information about the analysis of Java features is a

SonarSource 976 Jan 5, 2023
An extensible multilanguage static code analyzer.

PMD About PMD is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and

PMD 4.1k Jan 2, 2023
Tackle Data-intensive Validity Analyzer

Tackle-DiVA (Data-intensive Validity Analyzer) Tackle-DiVA is a command-line tool for data-centric application analysis. It imports a set of target ap

Konveyor 38 Oct 31, 2022
SpotBugs is FindBugs' successor. A tool for static analysis to look for bugs in Java code.

SpotBugs is the spiritual successor of FindBugs, carrying on from the point where it left off with support of its community. SpotBugs is licensed unde

null 2.9k Jan 4, 2023
Java library for parsing report files from static code analysis.

Violations Lib This is a Java library for parsing report files like static code analysis. Example of supported reports are available here. A number of

Tomas Bjerre 127 Nov 23, 2022
mobsfscan is a static analysis tool that can find insecure code patterns in your Android and iOS source code.

mobsfscan is a static analysis tool that can find insecure code patterns in your Android and iOS source code. Supports Java, Kotlin, Swift, and Objective C Code. mobsfscan uses MobSF static analysis rules and is powered by semgrep and libsast pattern matcher.

Mobile Security Framework 347 Dec 29, 2022
Inria 1.4k Dec 29, 2022
Astra: a Java tool for analysing and refactoring Java source code

What is Astra? Astra is a Java tool for analysing and refactoring Java source code. For example: "References to type A should instead reference type B

Alfa 51 Dec 26, 2022
Reformats Java source code to comply with Google Java Style.

google-java-format google-java-format is a program that reformats Java source code to comply with Google Java Style. Using the formatter from the comm

Google 4.8k Dec 31, 2022
Catch common Java mistakes as compile-time errors

Error Prone Error Prone is a static analysis tool for Java that catches common programming mistakes at compile-time. public class ShortSet { public

Google 6.3k Dec 31, 2022
A tool to help eliminate NullPointerExceptions (NPEs) in your Java code with low build-time overhead

NullAway: Fast Annotation-Based Null Checking for Java NullAway is a tool to help eliminate NullPointerExceptions (NPEs) in your Java code. To use Nul

Uber Open Source 3.2k Dec 29, 2022
OpenGrok is a fast and usable source code search and cross reference engine, written in Java

Copyright (c) 2006, 2020 Oracle and/or its affiliates. All rights reserved. OpenGrok - a wicked fast source browser OpenGrok - a wicked fast source br

Oracle 3.8k Jan 8, 2023
A free injection hacked client for Minecraft using Java-agents

Swift Swift is a free and open-source injection hacked client base for Minecraft using Java-agents. Issues If you notice any bugs, you can let us know

static final 36 Oct 8, 2022
A static analyzer for Java, C, C++, and Objective-C

Infer Infer is a static analysis tool for Java, C++, Objective-C, and C. Infer is written in OCaml. Installation Read our Getting Started page for det

Facebook 13.7k Dec 28, 2022
:coffee: SonarSource Static Analyzer for Java Code Quality and Security

Code Quality and Security for Java This SonarSource project is a code analyzer for Java projects. Information about the analysis of Java features is a

SonarSource 976 Jan 5, 2023
An extensible multilanguage static code analyzer.

PMD About PMD is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and

PMD 4.1k Jan 2, 2023
Bank Statement Analyzer Application that currently runs in terminal with the commands: javac Application.java java Application [file-name].csv GUI coming soon...

Bank Statement Analyzer Application that currently runs in terminal with the commands: javac Application.java java Application [file-name].csv GUI coming soon...

Hayden Hanson 0 May 21, 2022
Java - Packet Analyzer Application based on Java, Networking and Swing UI

Network-Packet-Tracer-using-Java Java - Packet Analyzer / Sniffing System Application based on Java, Networking and Swing UI Java - Packet Analyzer Ap

Muhammad Asad 6 Feb 3, 2022
Tackle Data-intensive Validity Analyzer

Tackle-DiVA (Data-intensive Validity Analyzer) Tackle-DiVA is a command-line tool for data-centric application analysis. It imports a set of target ap

Konveyor 38 Oct 31, 2022