Giter Club home page Giter Club logo

Comments (10)

jsotuyod avatar jsotuyod commented on May 27, 2024 1

@KengoTODA the exception does occur, but is managed and simply logged to stderr without the test failing.

from spotbugs.

KengoTODA avatar KengoTODA commented on May 27, 2024

I will try to reproduce this in issue-20 branch.

from spotbugs.

KengoTODA avatar KengoTODA commented on May 27, 2024

I'm still testing #61, which is necessary to test your class with our integration test. Here is current patch:

diff --git a/findbugs/src/test/java/edu/umd/cs/findbugs/detect/FindUnsatisfiedObligationTest.java b/findbugs/src/test/java/edu/umd/cs/findbugs/detect/FindUnsatisfiedObligationTest.java
new file mode 100644
index 0000000..a767df9
--- /dev/null
+++ b/findbugs/src/test/java/edu/umd/cs/findbugs/detect/FindUnsatisfiedObligationTest.java
@@ -0,0 +1,22 @@
+package edu.umd.cs.findbugs.detect;
+
+import static org.junit.Assert.assertThat;
+
+import static org.hamcrest.core.Is.is;
+
+import static org.hamcrest.collection.IsEmptyIterable.*;
+import org.junit.Test;
+
+import edu.umd.cs.findbugs.AbstractIntegrationTest;
+
+public class FindUnsatisfiedObligationTest extends AbstractIntegrationTest {
+    /**
+     * @see <a href="https://github.com/spotbugs/spotbugs/issues/60">GitHub
+     *      issue</a>
+     */
+    @Test
+    public void testIssue60() {
+        performAnalysis("Issue60.class");
+        assertThat(getBugCollection(), is(emptyIterable()));
+    }
+}
diff --git a/findbugsTestCases/src/java/Issue60.java b/findbugsTestCases/src/java/Issue60.java
new file mode 100644
index 0000000..b79f1b8
--- /dev/null
+++ b/findbugsTestCases/src/java/Issue60.java
@@ -0,0 +1,22 @@
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+import java.util.stream.Stream;
+
+public class Issue60 {
+
+    public static void create(URL url) {
+        try (InputStream in = url.openStream()) {
+            Properties p1 = new Properties();
+            p1.load(in);
+        } catch (IOException e) {
+        }
+    }
+
+    public Stream<String> keys() {
+        return Stream.<Properties> of()
+                .flatMap(p -> p.stringPropertyNames().stream());
+    }
+
+}

from spotbugs.

KengoTODA avatar KengoTODA commented on May 27, 2024

By #69, I confirmed that current master branch has no problem. @barney2k7 please have a try.

from spotbugs.

KengoTODA avatar KengoTODA commented on May 27, 2024

@jsotuyod Oh... I also confirmed this behaviour. I will try to update AbstractIntegrationTest to mark our build as failed.

from spotbugs.

jsotuyod avatar jsotuyod commented on May 27, 2024

Running javap on the compiled source we can see the offending code:

  public java.util.stream.Stream<java.lang.String> keys();
    descriptor: ()Ljava/util/stream/Stream;
    flags: ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         0: iconst_0
         1: anewarray     #3                  // class java/util/Properties
         4: invokestatic  #10                 // InterfaceMethod java/util/stream/Stream.of:([Ljava/lang/Object;)Ljava/util/stream/Stream;
         7: invokedynamic #11,  0             // InvokeDynamic #0:apply:()Ljava/util/function/Function;

And in the constant pool we can see:

Constant pool:
    #1 = Methodref          #16.#46       // java/lang/Object."<init>":()V
    #2 = Methodref          #47.#48       // java/net/URL.openStream:()Ljava/io/InputStream;
    #3 = Class              #49           // java/util/Properties
    #4 = Methodref          #3.#46        // java/util/Properties."<init>":()V
    #5 = Methodref          #3.#50        // java/util/Properties.load:(Ljava/io/InputStream;)V
    #6 = Methodref          #51.#52       // java/io/InputStream.close:()V
    #7 = Class              #53           // java/lang/Throwable
    #8 = Methodref          #7.#54        // java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V
    #9 = Class              #55           // java/io/IOException
   #10 = InterfaceMethodref #56.#57       // java/util/stream/Stream.of:([Ljava/lang/Object;)Ljava/util/stream/Stream;
   #11 = InvokeDynamic      #0:#63        // #0:apply:()Ljava/util/function/Function;

This happens because the invokedynamic is acting on the method handle, which of course, has no class name.

This is a bug on BCEL, that should override getReferenceType on INVOKEDYNAMIC to at least not throw a ClassFormatException. What do you think @mebigfatguy ?

In the meantime, we may rewrite the detector to handle INVOKEDYNAMIC separately.

from spotbugs.

mebigfatguy avatar mebigfatguy commented on May 27, 2024

yeah, should add a bug here http://issues.apache.org/jira/browse/BCEL

from spotbugs.

mebigfatguy avatar mebigfatguy commented on May 27, 2024

i suppose it should return Object?or....? i'll add it.

https://issues.apache.org/jira/browse/BCEL-284

from spotbugs.

jsotuyod avatar jsotuyod commented on May 27, 2024

You are amazing! Thanks for the quick fix

I guess for the time being we can wait for a BCEL 6.1 release / use a snapshot until we reach the point of releasing Spotbugs 3.1.0

from spotbugs.

KengoTODA avatar KengoTODA commented on May 27, 2024

This problem should be solved by #69. I will close this issue.

from spotbugs.

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.