-
Notifications
You must be signed in to change notification settings - Fork 112
Fix ClassCastException in MagicNumberDiagnostic with soft error handling #3486
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
Draft
Copilot
wants to merge
22
commits into
develop
Choose a base branch
from
copilot/fix-3485
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
337d432
Initial plan for issue
Copilot 80a646b
Fix ClassCastException in MagicNumberDiagnostic with soft error handling
Copilot 50e7a28
Implement general solution for ClassCastException in diagnostic confi…
Copilot 240c0fe
Simplify ClassCastException handling to just try/catch with error log…
Copilot 503081e
Implement localized error messages and crash test for DiagnosticBeanP…
Copilot d60200f
Address code review feedback: change log level, fix localization, imp…
Copilot ad3410a
Use getBean for DiagnosticBeanPostProcessor in test instead of manual…
Copilot 1681c41
Add reflection-based verification of diagnostic parameter values afte…
Copilot d21e17d
Use DiagnosticObjectProvider and autowired DiagnosticBeanPostProcesso…
Copilot ea69b6e
Replace reflection with getter method for DiagnosticsOptions configur…
Copilot 7346b69
Add verification of default authorized numbers in test as requested
Copilot df49d65
Implement JSON schema validation for diagnostic parameters
Copilot dae5993
Implement cached JSON schema validation for diagnostic parameters per…
Copilot 0443adb
Extract DiagnosticParameterValidator class to enable Spring caching f…
Copilot 7bdfb53
Add Javadoc to DiagnosticParameterValidator class and use @Getter(laz…
Copilot dafc798
Fix deprecated method usage and Spring Bean warnings in DiagnosticBea…
Copilot 7a4c86d
Add ROLE_INFRASTRUCTURE to core infrastructure beans to resolve Sprin…
Copilot d69d92d
Complete Spring Bean warnings fix by adding ROLE_INFRASTRUCTURE to al…
Copilot 7276b9d
Remove inappropriate ROLE_INFRASTRUCTURE annotations from regular bea…
Copilot 6e38274
Fix failing tests and eliminate Spring Bean warnings by removing sche…
Copilot 631c220
Reintegrate JSON schema validation in DiagnosticBeanPostProcessor wit…
Copilot 291d79b
Restore DiagnosticParameterValidator component with infrastructure ro…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...x/bsl/languageserver/diagnostics/infrastructure/DiagnosticBeanPostProcessor_en.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
diagnosticConfigurationError=Failed to configure diagnostic ''{0}''. Diagnostic will use default configuration: {1} |
1 change: 1 addition & 0 deletions
1
...x/bsl/languageserver/diagnostics/infrastructure/DiagnosticBeanPostProcessor_ru.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
diagnosticConfigurationError=Ошибка конфигурирования диагностики ''{0}''. Диагностика будет использовать конфигурацию по умолчанию: {1} |
98 changes: 98 additions & 0 deletions
98
...syntax/bsl/languageserver/diagnostics/infrastructure/DiagnosticBeanPostProcessorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* This file is a part of BSL Language Server. | ||
* | ||
* Copyright (c) 2018-2025 | ||
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* | ||
* BSL Language Server is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3.0 of the License, or (at your option) any later version. | ||
* | ||
* BSL Language Server is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with BSL Language Server. | ||
*/ | ||
package com.github._1c_syntax.bsl.languageserver.diagnostics.infrastructure; | ||
|
||
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration; | ||
import com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions; | ||
import com.github._1c_syntax.bsl.languageserver.diagnostics.BSLDiagnostic; | ||
import com.github._1c_syntax.bsl.languageserver.diagnostics.MagicNumberDiagnostic; | ||
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCode; | ||
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo; | ||
import com.github._1c_syntax.bsl.languageserver.utils.Resources; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
@SpringBootTest | ||
class DiagnosticBeanPostProcessorTest { | ||
|
||
@Autowired | ||
private LanguageServerConfiguration configuration; | ||
|
||
@Autowired | ||
private Map<Class<? extends BSLDiagnostic>, DiagnosticInfo> diagnosticInfos; | ||
|
||
@Autowired | ||
private Resources resources; | ||
|
||
@Test | ||
void testPostProcessAfterInitializationWithClassCastExceptionShouldNotCrash() throws Exception { | ||
// given | ||
var diagnosticBeanPostProcessor = new DiagnosticBeanPostProcessor(configuration, diagnosticInfos, resources); | ||
var diagnostic = new MagicNumberDiagnostic(); | ||
nixel2007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Create configuration that will cause ClassCastException | ||
var diagnosticsOptions = new DiagnosticsOptions(); | ||
var parameters = new HashMap<String, Either<Boolean, Map<String, Object>>>(); | ||
|
||
Map<String, Object> configMap = new HashMap<>(); | ||
List<String> invalidAuthorizedNumbers = new ArrayList<>(); | ||
invalidAuthorizedNumbers.add("-1"); | ||
invalidAuthorizedNumbers.add("0"); | ||
invalidAuthorizedNumbers.add("1"); | ||
configMap.put("authorizedNumbers", invalidAuthorizedNumbers); // This should be a String but is a List | ||
|
||
parameters.put("MagicNumber", Either.forRight(configMap)); | ||
diagnosticsOptions.setParameters(parameters); | ||
|
||
// Use reflection to set the diagnosticsOptions in configuration | ||
Field diagnosticsOptionsField = configuration.getClass().getDeclaredField("diagnosticsOptions"); | ||
diagnosticsOptionsField.setAccessible(true); | ||
diagnosticsOptionsField.set(configuration, diagnosticsOptions); | ||
nixel2007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// when/then - should not throw any exception, diagnostic configuration should fail gracefully | ||
assertDoesNotThrow(() -> { | ||
// First set the diagnostic info (postProcessBeforeInitialization) | ||
var result1 = diagnosticBeanPostProcessor.postProcessBeforeInitialization(diagnostic, "testBean"); | ||
|
||
// Then configure it (postProcessAfterInitialization) | ||
var result2 = diagnosticBeanPostProcessor.postProcessAfterInitialization(result1, "testBean"); | ||
|
||
// Verify the diagnostic bean is returned (normal behavior even with configuration error) | ||
assertThat(result2).isSameAs(diagnostic); | ||
}); | ||
|
||
// Verify the diagnostic exists and has info set (basic functionality should work) | ||
nixel2007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assertThat(diagnostic.getInfo()).isNotNull(); | ||
assertThat(diagnostic.getInfo().getCode()).isNotNull(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.