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

0.8 regression: IndexOutOfBoundsException when collecting dependencies #110

Open
ZacSweers opened this issue Aug 7, 2024 · 2 comments
Open
Labels
bug Something isn't working lang:kotlin Kotlin DSL more information needed

Comments

@ZacSweers
Copy link
Collaborator

Working on trying to figure out which file it sees this on

Caused by: java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
        at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
        at java.base/java.util.Objects.checkIndex(Objects.java:385)
        at java.base/java.util.ArrayList.get(ArrayList.java:427)
        at cash.grammar.kotlindsl.utils.DependencyExtractor.findIdentifier(DependencyExtractor.kt:253)
        at cash.grammar.kotlindsl.utils.DependencyExtractor.parseDependencyDeclaration(DependencyExtractor.kt:154)
        at cash.grammar.kotlindsl.utils.DependencyExtractor.collectDependencies(DependencyExtractor.kt:48)
        at com.squareup.sort.kotlin.KotlinSorter.enterNamedBlock(KotlinSorter.kt:84)
        at com.squareup.cash.grammar.KotlinParser$NamedBlockContext.enterRule(KotlinParser.java:1491)
        at org.antlr.v4.runtime.tree.ParseTreeWalker.enterRule(ParseTreeWalker.java:50)
        at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:33)
        at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
        at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
        at cash.grammar.kotlindsl.parse.Parser.listener(Parser.kt:96)
        at com.squareup.sort.kotlin.KotlinSorter$Companion.of(KotlinSorter.kt:182)
        at com.squareup.sort.Sorter$Companion.of(Sorter.kt:20)
        at com.squareup.sort.SortCommand$sort$1.invoke(SortCommand.kt:118)
        at com.squareup.sort.SortCommand$sort$1.invoke(SortCommand.kt:116)
        at com.squareup.sort.SortCommand.sort$lambda$0(SortCommand.kt:116)

@autonomousapps autonomousapps added bug Something isn't working more information needed lang:kotlin Kotlin DSL labels Aug 7, 2024
@ZacSweers
Copy link
Collaborator Author

ZacSweers commented Sep 11, 2024

I'm not 100% sure but I think this reproduces it in a slightly different way: slackhq/foundry#934

If you clone that branch and run ./gradlew sortDependencies it'll crash just before the trace above does

> Task :agp-handlers:agp-handler-api:sortDependencies FAILED
Exception in thread "main" java.lang.NullPointerException
        at cash.grammar.kotlindsl.utils.DependencyExtractor.parseDependencyDeclaration(DependencyExtractor.kt:189)
        at cash.grammar.kotlindsl.utils.DependencyExtractor.collectDependencies(DependencyExtractor.kt:48)
        at com.squareup.sort.kotlin.KotlinSorter.enterNamedBlock(KotlinSorter.kt:84)
        at com.squareup.cash.grammar.KotlinParser$NamedBlockContext.enterRule(KotlinParser.java:1491)
        at org.antlr.v4.runtime.tree.ParseTreeWalker.enterRule(ParseTreeWalker.java:50)
        at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:33)
        at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
        at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:36)
        at cash.grammar.kotlindsl.parse.Parser.listener(Parser.kt:96)
        at com.squareup.sort.kotlin.KotlinSorter$Companion.of(KotlinSorter.kt:182)
        at com.squareup.sort.Sorter$Companion.of(Sorter.kt:20)
        at com.squareup.sort.SortCommand$sort$1.invoke(SortCommand.kt:118)
        at com.squareup.sort.SortCommand$sort$1.invoke(SortCommand.kt:116)
        at com.squareup.sort.SortCommand.sort$lambda$0(SortCommand.kt:116)

The failing file seems uninteresting on its own

/*
 * Copyright (C) 2023 Slack Technologies, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
plugins {
  kotlin("jvm")
  alias(libs.plugins.mavenPublish)
  alias(libs.plugins.lint)
}

dependencies {
  lintChecks(libs.gradleLints)
  implementation(libs.guava)

  compileOnly(gradleApi())
  compileOnly(libs.agp)

  testImplementation(gradleApi())
  testImplementation(libs.agp)
  testImplementation(libs.junit)
  testImplementation(libs.truth)
}

@ZacSweers
Copy link
Collaborator Author

ZacSweers commented Sep 11, 2024

after testing, it looks like the problem is the gradleApi() usages. If I comment them out, they work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lang:kotlin Kotlin DSL more information needed
Projects
None yet
Development

No branches or pull requests

2 participants