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

Lambda methods reported as missing classes #527

Open
iloveeclipse opened this issue Jan 11, 2018 · 26 comments
Open

Lambda methods reported as missing classes #527

iloveeclipse opened this issue Jan 11, 2018 · 26 comments
Assignees

Comments

@iloveeclipse
Copy link
Member

This is a side effect of not properly supporting INVOKEDYNAMIC instruction (issue #6): the snippet below generates "The following classes needed for SpotBugs analysis on project A were missing: run" warning on every analysis in Eclipse.
This is most likely same as issue spotbugs/discuss/issues/29.

public class Client {	
	public void errorOnLambda() {
		Object o = getObject();
		if (o != null) { 
			useRunnable(() -> toString());
		}
		o.hashCode();
	}

	public Object getObject() {
		return null;
	}

	public void useRunnable(Runnable listener) {
	}
}

While we still lacks the proper INVOKEDYNAMIC support, we should at least make sure we don't raise stupid warnings.

@iloveeclipse iloveeclipse added this to the SpotBugs 3.1.2 milestone Jan 11, 2018
@iloveeclipse iloveeclipse self-assigned this Jan 11, 2018
iloveeclipse added a commit that referenced this issue Jan 13, 2018
The lambda representation makes no sense for XMethod "classical"
instruction attributes are filled with garbage, causing the code later
to produce crazy errors (looking for non existing types etc).

We should NOT be called here from our code, but 3rd party code still may
use this method. So *at least* provide a valid class name, which is
(don't ask me why) is encoded in the first argument type of the lambda.
But even this above I fear will surprise the callers and probably fail
in some cases, so use Object as last "safe" resort.

See issue #527
iloveeclipse added a commit that referenced this issue Jan 13, 2018
iloveeclipse added a commit that referenced this issue Jan 21, 2018
The lambda representation makes no sense for XMethod "classical"
instruction attributes are filled with garbage, causing the code later
to produce crazy errors (looking for non existing types etc).

We should NOT be called here from our code, but 3rd party code still may
use this method. So *at least* provide a valid class name, which is
(don't ask me why) is encoded in the first argument type of the lambda.
But even this above I fear will surprise the callers and probably fail
in some cases, so use Object as last "safe" resort.

See issue #527
iloveeclipse added a commit that referenced this issue Jan 21, 2018
@iloveeclipse iloveeclipse mentioned this issue Jan 21, 2018
1 task
@iloveeclipse
Copy link
Member Author

Merged in 3.1 and master.

@Vampire
Copy link
Contributor

Vampire commented Feb 13, 2019

This still happens in 3.1.11:

<BugCollection version="3.1.11" sequence="0" tim.estamp="1550070145794" analysisTimestamp="1550075180425" release="">
...
  <Errors errors="0" missingClasses="14">
    <MissingClass>accept</MissingClass>
    <MissingClass>actionPerformed</MissingClass>
    <MissingClass>apply</MissingClass>
    <MissingClass>changed</MissingClass>
    <MissingClass>deliverSelectedHuman</MissingClass>
    <MissingClass>get</MissingClass>
    <MissingClass>getLineData</MissingClass>
    <MissingClass>handle</MissingClass>
    <MissingClass>handleEvent</MissingClass>
    <MissingClass>makeConcatWithConstants</MissingClass>
    <MissingClass>objectSelected</MissingClass>
    <MissingClass>run</MissingClass>
    <MissingClass>test</MissingClass>
    <MissingClass>valueChanged</MissingClass>
  </Errors>
  <FindBugsSummary timestamp="Wed, 13 Feb 2019 16:02:25 +0100" total_classes="1193" referenced_classes="2829" total_bugs="114" total_size="64357" num_packages="124" java_version="11.0.1" vm_version="11.0.1+13" cpu_seconds="264.19" clock_seconds="104.04" peak_mbytes="4467.56" alloc_mbytes="3072.00" gc_seconds="1.93" priority_2="113" priority_1="1">
...

@Vampire
Copy link
Contributor

Vampire commented Feb 14, 2019

I also tested with Java 8 and the SpotBugs 3.1.2 like in the milestone, there it is exactly the same.

@KengoTODA KengoTODA reopened this Feb 14, 2019
@d1ss0nanz
Copy link

I can confirm, the issue still exists.

@ati90ati
Copy link

In a bigger project I've using spotbugs to detect issues and I have these warning on the output while building:

The following classes needed for analysis were missing:
  apply
  test
  makeConcatWithConstants
  run
  get

I've created a small example to reproduce this bug.
In the repo the Java version used is 11, but these errors happens with Java 8 also.

https://github.com/ati90ati/bugreport-spotbugs-gradle-plugin-logging

In the repo I'm getting this unwanted output:

The following classes needed for analysis were missing:
  apply

I hope that you guys can find a solution to fix this bug.

@abcfy2
Copy link

abcfy2 commented May 5, 2019

Same issue for 3.1.12:

> Task :spotbugsMain
The following classes needed for analysis were missing:
  handle
  accept

> Task :spotbugsMain FAILED

@clistoq
Copy link

clistoq commented Jul 4, 2019

On Maven, also can see this issue.
Env:

  • spotbugs: 3.1.12
  • mvn: 3.6.1
  • findsec: 1.9.0
  • fb-contrib: 7.4.3.sb

Stacktrace:
[java] The following classes needed for analysis were missing: [java] test [java] accept [java] apply [java] get [java] run [java] onRead [java] go [java] adjustInto [java] handle [java] Warnings generated: 89 [java] Missing classes: 9

@testn
Copy link

testn commented Apr 9, 2020

still happens in SpotBugs 4.0.0

@Omniscience619
Copy link

In a bigger project I've using spotbugs to detect issues and I have these warning on the output while building:

The following classes needed for analysis were missing:
  apply
  test
  makeConcatWithConstants
  run
  get

I've created a small example to reproduce this bug.
In the repo the Java version used is 11, but these errors happens with Java 8 also.

https://github.com/ati90ati/bugreport-spotbugs-gradle-plugin-logging

In the repo I'm getting this unwanted output:

The following classes needed for analysis were missing:
  apply

I hope that you guys can find a solution to fix this bug.

Pardon my dumb question, but do these warnings mean that the findbugs plugin didn't run at all, or simply worked, but couldn't find these classes? I wasn't able to understand what's exactly going on in the plugin when it encounters this error.

@ati90ati
Copy link

The plugin worked, just the output was very disturbing, especially when you have more modules.

@jonathansantilli
Copy link

jonathansantilli commented Aug 12, 2020

Hello @ati90ati, you mentioned that the plugin still works, good.

have you noticed if the results are affected by that behavior? like the one you describe here

I have noticed an increase in False Positives when that error shows up.

@DanielFran
Copy link

I add this issue ~ 2 years ago, we were using an old Sonar version (v6.7.x), we were trying to migrate sonar to a newer version compatible with Java 11, but the false positive in the new Spotbug version used were blocking the pipelines. We needed to rollback to that Sonar version and at that time this was blocking us for example to migrate projects from Java 8 to 11....
We never try again to use projects with Java 11 till today 👎

@ati90ati
Copy link

ati90ati commented Aug 12, 2020

@jonathansantilli I haven't noticed any problem in the behavior. Spotbugs seemed to work well, only it had a disturbing output.

@DanielFran You can suppress warnings (even false positives) in Spotbugs so this shouldn't stop you to upgrade to Java 11 (some examples: https://github.com/undertow-io/undertow/blob/master/spotbugs-exclude.xml).

@rios0rios0
Copy link

rios0rios0 commented Jun 28, 2021

Hello guys!
I think this bug still happens in newer version:

[INFO] --- spotbugs-maven-plugin:4.2.3:spotbugs (spotbugs) @ API ---
[INFO] Fork Value is true
     [java] Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
     [java] The following classes needed for analysis were missing:
     [java]   makeConcatWithConstants
     [java]   accept
     [java]   apply
     [java]   run
     [java]   test
[INFO] Done SpotBugs Analysis....

@dmivankov
Copy link
Contributor

Still happens with 4.3.0.
If used with -exitcode flag it makes tests fail on lambdas. And since this isn't reported as usual bug, it's not possible to manually ignore specific lambdas (or say regexp-ignore any missing classes without packages).
On the other hand, the feature is useful as it can help detecting NoClassDefFoundError.
As a workaround it could be possible to analyze stderr in a post-processing script

binkley pushed a commit to binkley/modern-java-practices that referenced this issue Aug 20, 2021
For Spotbugs, the Gradle plugin by default checks tests: teach Maven to
do the same.

Do note warnings from Spotbugs for (depending on your Java and/or
platform version):
- apply
- call
- execute
- makeConcatWithConstants

The complaint is "classes needed for analysis were missing", however,
these are not classes in the usual sense, but internal JDK
implementation details related to lambdas and `invokedynamic`.

See spotbugs/spotbugs#527.
@slott
Copy link

slott commented Sep 1, 2022

Still happening on 5.0.10...

The following classes needed for analysis were missing:
java.rmi.Remote
java.util.Arrays$ArrayList
SpotBugs ended with exit code 3

@CreeTar
Copy link

CreeTar commented Nov 29, 2022

Using Java 11 still a problem, is there an celebration for this bugs 5th year anniversary? Off to 5 more years :)

@delanym
Copy link

delanym commented Apr 14, 2023

I only get this, i.e.

     [java] The following classes needed for analysis were missing:
     [java]   makeConcatWithConstants
     [java]   test
     [java]   apply
     [java]   accept
     [java]   actionPerformed
     [java]   run
     [java]   compare
     [java]   get

when I include findsecbugs

        <plugin>
          <groupId>com.github.spotbugs</groupId>
          <artifactId>spotbugs-maven-plugin</artifactId>
          <version>4.7.3.4</version>
          <configuration>
            <plugins>
              <plugin>
                <groupId>com.h3xstream.findsecbugs</groupId>
                <artifactId>findsecbugs-plugin</artifactId>
                <version>1.12.0</version>
              </plugin>
            </plugins>
          </configuration>
Apache Maven 3.9.0 (9b58d2bad23a66be161c4664ef21ce219c2c8584)
Maven home: /home/sol/.m2/wrapper/dists/apache-maven-3.9.0/86b67b91
Java version: 20-ea, vendor: Private Build, runtime: /usr/lib/jvm/java-20-openjdk-amd64
Default locale: en_ZA, platform encoding: UTF-8
OS name: "linux", version: "5.19.0-38-generic", arch: "amd64", family: "unix"

@in-fke
Copy link

in-fke commented Apr 27, 2023

Still a Bug after more than five years.

@SimSonic
Copy link

SimSonic commented Jun 16, 2023

In my case list is bigger:

     [java] The following classes needed for analysis were missing:
     [java]   makeConcatWithConstants
     [java]   apply
     [java]   equals
     [java]   toString
     [java]   hashCode
     [java]   get
     [java]   accept
     [java]   test
     [java]   customize
     [java]   doInTransaction
     [java]   resolve
     [java]   applyAsInt
     [java]   getAddress
     [java]   getAsBoolean
     [java]   run
     [java]   handleError
     [java]   getTags
     [java]   call
     [java]   typeSwitch
     [java]   applyAsLong
     [java]   getSpecification
     [java]   applyAsDouble
     [java]   configure
     [java]   mapRow
     [java]   doInPreparedStatement

jdk 20
spotbugs 4.7.3.0
findsecbugs 1.12.0

@Vampire
Copy link
Contributor

Vampire commented Jun 26, 2023

It even got worse now, because it is reported once per report.
so if you have XML and HTML report configured, you get the message printed twice. :-(

@victorwss
Copy link

@delanym I also only get this when using find-sec-bugs.

@soloturn
Copy link

@JuditKnoll you happen to know what could be done here?

@JuditKnoll
Copy link
Collaborator

@soloturn I'm sorry, I don't know. I haven't looked into this issue properly, but for me it looks like it may be a find-sec-bugs issue. I'm not really familiar how exactly SpotBugs and its plugins interacts with each other.
There was a workaround merged into find-sec-bugs recently (find-sec-bugs/find-sec-bugs#690), which is marked as "may solve this issue", but there was no new find-sec-bugs released since then.

@victorherraiz
Copy link

victorherraiz commented Mar 20, 2024

Version 1.13.0, released almost a month ago, of find-sec-bugs does not solve the problem for me.

@bdellegrazie
Copy link

Version 1.13.0 of find-sec-bugs doesn't solve this, even with the -Dfindsecbugs.taint.workaroundvisitinvokedynamic=true enabled or not, I see no difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests