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.

Redundant cast in generated component

See original GitHub issue

I have a redundant cast in one of my generated component implementations: this.provideFooProvider = DoubleCheck.provider((Provider) provideRealFooProvider); where Foo is an interface and RealFoo is the concrete type.

@Module public abstract class FooModule {
  @AppScope @Provides static RealFoo provideRealFoo() {
    return Foo.create();

  @AppScope @Binds abstract Foo provideFoo(RealFoo realFoo);

This is such a minor thing, and it doesn’t end up in the bytecode. Totally close this if it’s uninteresting.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

TWiStErRobcommented, Aug 1, 2019

@ronshapiro @gk5885 I just ran into this while upgrading from 2.16 to 2.23.2. If you’re not going to go with ? extends would it make sense to at least @SuppressWarnings("cast") on that method so we can use -Werror on our codebases?

By the way, if someone find this issue, the TL;DR workaround is to open up the visibility of the implementation (so that the generated component can access it):

package a;
public class MyModule {
    Interface bind(Implementation impl);

package a;
public interface Interface {}

package a;
-class Implementation implements Interface {}
+public class Implementation implements Interface {}

package b;
import a.MyModule;
@Component(modules = {MyModule.class})

Exact error message that lead me here for SEO:

> Task :app:compileDebugJavaWithJavac
warning: [cast] redundant cast to Provider
        this.bindProvider = DoubleCheck.provider((Provider) implementationProvider);
NightlyNexuscommented, Jun 28, 2017

Yes, my component is in a different package, and those are my fields.

Oh, that makes sense. Thank you for the fantastic explanation! I appreciate it! I was super curious about the cause. 🌟

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java redundant casts required in generic method
I was looking at a way to optimize some things in our code base with generic functions. There is a function with return...
Read more >
Java static code analysis: Redundant casts should not be used
Redundant casts should not be used ... Unnecessary casting expressions make the code harder to read and understand. Noncompliant Code Example. public void...
Read more >
"Redundant cast" warning in generated java code when using ...
There are some "redundant cast" warnings in generated java code when the message type has a one_of field: The message: message Type {...
Read more >
Code Inspection: Redundant cast - ReSharper - JetBrains
According to C# documentation, explicit conversion (cast) is redundant in the following cases: Conversions from derived classes to base classes.
Read more >
[JDK-8054492] Casting can result in redundant null checks in ...
I talked with Paul and he is asking to not generate uncommon trap for null check in Class.cast() in all cases - just...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found