Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,12 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
gradleTaskFile = ""
}

mavenIndexPath, ok := config.ProviderSpecificConfig[MAVEN_INDEX_PATH].(string)
mavenSHASearchIndex, ok := config.ProviderSpecificConfig[MAVEN_INDEX_PATH].(string)
if !ok {
log.Info("unable to find the maven index path in the provider specific config")
}

mavenOpenSourceIndex, ok := config.ProviderSpecificConfig[labels.ProviderSpecificConfigOpenSourceDepListKey].(string)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add error handling for missing config key.

The retrieval of mavenOpenSourceIndex is missing the ok check and logging that was added for mavenSHASearchIndex on lines 281-284. This inconsistency could lead to silently using an empty string if the config key is not found.

Apply this diff to add consistent error handling:

 	mavenOpenSourceIndex, ok := config.ProviderSpecificConfig[labels.ProviderSpecificConfigOpenSourceDepListKey].(string)
+	if !ok {
+		log.Info("unable to find the maven open source index path in the provider specific config")
+	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
mavenOpenSourceIndex, ok := config.ProviderSpecificConfig[labels.ProviderSpecificConfigOpenSourceDepListKey].(string)
mavenOpenSourceIndex, ok := config.ProviderSpecificConfig[labels.ProviderSpecificConfigOpenSourceDepListKey].(string)
if !ok {
log.Info("unable to find the maven open source index path in the provider specific config")
}
🤖 Prompt for AI Agents
In
external-providers/java-external-provider/pkg/java_external_provider/provider.go
around line 286, the code reads mavenOpenSourceIndex, ok :=
config.ProviderSpecificConfig[labels.ProviderSpecificConfigOpenSourceDepListKey].(string)
but does not handle the case when ok is false; add the same nil/ok check and
logging that exists for mavenSHASearchIndex (lines ~281-284): if the key is
missing or not a string, log a descriptive error (using the same
providerLogger/Errorf or Warnf used earlier) including the config key name and
current ProviderSpecificConfig contents, and set mavenOpenSourceIndex to an
empty string or handle it consistently with the existing behavior used for
mavenSHASearchIndex.

// each service client should have their own context
downloadCtx, cancelFunc := context.WithCancel(ctx)
// location can be a coordinate to a remote mvn artifact
Expand All @@ -309,7 +310,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
Config: config,
MvnSettingsFile: mavenSettingsFile,
MvnInsecure: mavenInsecure,
MavenIndexPath: mavenIndexPath,
MavenIndexPath: mavenSHASearchIndex,
Labeler: openSourceLabeler,
GradleTaskFile: gradleTaskFile,
}, log)
Expand Down Expand Up @@ -341,7 +342,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
depsLocationCache: make(map[string]int),
includedPaths: provider.GetIncludedPathsFromConfig(config, false),
buildTool: buildTool,
mvnIndexPath: mavenIndexPath,
mvnIndexPath: mavenOpenSourceIndex,
mvnSettingsFile: mavenSettingsFile,
}, provider.InitConfig{}, nil
} else if lspServerPath == "" {
Expand Down Expand Up @@ -481,7 +482,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
depsLocationCache: make(map[string]int),
includedPaths: provider.GetIncludedPathsFromConfig(config, false),
buildTool: buildTool,
mvnIndexPath: mavenIndexPath,
mvnIndexPath: mavenOpenSourceIndex,
mvnSettingsFile: mavenSettingsFile,
}

Expand Down
Loading