GithubHelp home page GithubHelp logo

Comments (5)

ThrawnCA avatar ThrawnCA commented on June 2, 2024

Sample code to reproduce:

package findbugs.sample;

public class TestRuntimeExceptionOnImplementingClass implements ThrowsRuntimeException {
    @Override
    public String someMethod() {
        return "foo";
    }
}

interface ThrowsRuntimeException {
    public Object someMethod() throws RuntimeException;
}

The rule should fire for the interface, but not for the class.

from fb-contrib.

ThrawnCA avatar ThrawnCA commented on June 2, 2024

Output from javap -v showing generated method:

Classfile findbugs/sample/TestRuntimeExceptionOnImplementingClass.class
  Last modified 31/07/2015; size 673 bytes
  MD5 checksum 8f8e7aa015c835f6a217ba9266e663b9
  Compiled from "TestRuntimeExceptionOnImplementingClass.java"
public class findbugs.sample.TestRuntimeExceptionOnImplementingClass implements findbugs.sample.ThrowsRuntimeException
  SourceFile: "TestRuntimeExceptionOnImplementingClass.java"
  minor version: 0
  major version: 51
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #5.#21         //  java/lang/Object."<init>":()V
   #2 = String             #22            //  foo
   #3 = Methodref          #4.#23         //  findbugs/sample/TestRuntimeExceptionOnImplementingClass.someMethod:()Ljava/lang/String;
   #4 = Class              #24            //  findbugs/sample/TestRuntimeExceptionOnImplementingClass
   #5 = Class              #25            //  java/lang/Object
   #6 = Class              #26            //  findbugs/sample/ThrowsRuntimeException
   #7 = Utf8               <init>
   #8 = Utf8               ()V
   #9 = Utf8               Code
  #10 = Utf8               LineNumberTable
  #11 = Utf8               LocalVariableTable
  #12 = Utf8               this
  #13 = Utf8               Lfindbugs/sample/TestRuntimeExceptionOnImplementingClass;
  #14 = Utf8               someMethod
  #15 = Utf8               ()Ljava/lang/String;
  #16 = Utf8               ()Ljava/lang/Object;
  #17 = Utf8               Exceptions
  #18 = Class              #27            //  java/lang/RuntimeException
  #19 = Utf8               SourceFile
  #20 = Utf8               TestRuntimeExceptionOnImplementingClass.java
  #21 = NameAndType        #7:#8          //  "<init>":()V
  #22 = Utf8               foo
  #23 = NameAndType        #14:#15        //  someMethod:()Ljava/lang/String;
  #24 = Utf8               findbugs/sample/TestRuntimeExceptionOnImplementingClass
  #25 = Utf8               java/lang/Object
  #26 = Utf8               findbugs/sample/ThrowsRuntimeException
  #27 = Utf8               java/lang/RuntimeException
{
  public findbugs.sample.TestRuntimeExceptionOnImplementingClass();
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0       
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return        
      LineNumberTable:
        line 3: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
               0       5     0  this   Lfindbugs/sample/TestRuntimeExceptionOnImplementingClass;

  public java.lang.String someMethod();
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: ldc           #2                  // String foo
         2: areturn       
      LineNumberTable:
        line 6: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
               0       3     0  this   Lfindbugs/sample/TestRuntimeExceptionOnImplementingClass;

  public java.lang.Object someMethod() throws java.lang.RuntimeException;
    flags: ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0       
         1: invokevirtual #3                  // Method someMethod:()Ljava/lang/String;
         4: areturn       
      LineNumberTable:
        line 3: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
               0       5     0  this   Lfindbugs/sample/TestRuntimeExceptionOnImplementingClass;
    Exceptions:
      throws java.lang.RuntimeException
}

Perhaps the solution is to check for the ACC_SYNTHETIC flag?

from fb-contrib.

mebigfatguy avatar mebigfatguy commented on June 2, 2024

ah, i just have to ignore synthetic methods, ok. thanks for the report.

from fb-contrib.

mebigfatguy avatar mebigfatguy commented on June 2, 2024

fixed in commit with hash 0159e44

thanks again for the report.

from fb-contrib.

ThrawnCA avatar ThrawnCA commented on June 2, 2024

Thanks!

By the way, if you put a # before the issue number in your commits, then Github will automatically link them.

from fb-contrib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.