question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RemoveUnusedimports removes used imports

See original GitHub issue

I ran this recipe on a few private repositories, and I had some compilation failures because of imports that where removed, but were in fact used. I fail to fin a pattern to explain the error, and thus create a unit test: sometimes the class was used in javadoc (@throws or @link), sometimes in annotations, …

So I played a bit with Moderne to reproduce on some public repositories. Here’s one: https://github.com/code4craft/webmagic/pull/1037/files

[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ webmagic-extension ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 24 source files to /tmp/webmagic/webmagic-extension/target/test-classes
[INFO] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/MockPageModelPipeline.java: Some input files use or override a deprecated API.
[INFO] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/MockPageModelPipeline.java: Recompile with -Xlint:deprecation for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[932,26] cannot find symbol
  symbol:   class Request
  location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[932,43] cannot find symbol
  symbol:   class Task
  location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[932,12] cannot find symbol
  symbol:   class Page
  location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[933,9] cannot find symbol
  symbol:   class Page
  location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[933,25] cannot find symbol
  symbol:   class Page
  location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[936,29] cannot find symbol
  symbol:   class Request
  location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[ERROR] /tmp/webmagic/webmagic-extension/src/test/java/us/codecraft/webmagic/downloader/MockGithubDownloader.java:[937,25] cannot find symbol
  symbol:   class PlainText
  location: class us.codecraft.webmagic.downloader.MockGithubDownloader
[INFO] 7 errors 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
traceyyoshimacommented, Oct 26, 2021

@murdos quick update - this should be fixed on main through NoMissingTypes.

We’re working on a solution so that shared namespaces like us.codecraft.webmagic.SpiderTest will contain type info. But NoMissingTypes will prevent used imports from being removed unexpectedly.

1reaction
traceyyoshimacommented, Nov 30, 2021

@murdos the new type cache accounts for the same FQN in multiple packages, but we’re still working on a release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Removed Used import · Issue #1085 · diffplug/spotless - GitHub
Hi Team, When trying to execute ./gradlew clean spotlessApply, it's removing one of the used imports. The project is on Java 8, ...
Read more >
RemoveUnused · Scalafix - Scala Center
Removes unused imports and terms that reported by the compiler under -Ywarn-unused. ... Remove unused imports: // before import scala.
Read more >
How to remove unused imports in Intellij IDEA on commit?
Choose the project/module you want to remove unused import from in Project view. Then from Code menu choose Optimize imports and confirm with...
Read more >
RemoveUnusedImports - Error Prone
The check has no known bugs. If it reports an unused import that looks like it was actually used, try removing it and...
Read more >
How to enable "remove unused imports"
Preferences->Editor->Auto Import->Optimize Imports on the Fly will automatically remove unuxed imports. 5. Avatar. Stephen Boesch · Created ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found