Skip to content

"File name too long" error occurs when diagnostic reports are created for factories with a long enough package + name combo #1303

@JoelWilcox

Description

@JoelWilcox

Description

This error specifically happens when the reports destination has been set and a report is attempted to be created for a provider factory where "provider-factory-$factoryFqName" exceeds the file name length. We run into this in instances where we've generated a binding container from a custom-annotated inner class of another class, but it could also occur with a source file with sufficiently long package + class name combination.

Self-contained Reproducer

PR coming shortly with a test to cover this and incremental fix, but here's an example that causes the failure:

package com.squareup.feature.featureflags

interface FeatureFlag

object RealProductionLoremIpsumFunctionalityFeatureFlagWrapper {
  @ContributesFeatureFlag
  object AllowLoremIpsumFunctionalitySemiLongNameFeatureFlag : FeatureFlag
}
package anvil.register.featureflags.com.squareup.feature.featureflags

// In this example, this binding container would normally be Anvil- or KSP-generated code based on the above feature flag and a custom contribution annotation
@BindingContainer
@ContributesTo(scope = AppScope::class)
public object RealProductionLoremIpsumFunctionalityFeatureFlagWrapper_AllowLoremIpsumFunctionalitySemiLongNameFeatureFlag {
  @Provides
  @IntoSet
  public fun providesAllowLoremIpsumFunctionalitySemiLongNameFeatureFlag(): FeatureFlag = RealProductionLoremIpsumFunctionalityFeatureFlagWrapper.AllowLoremIpsumFunctionalitySemiLongNameFeatureFlag
}

Metro version

0.7.2

Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions