Skip to content

Conversation

@devmehtabd
Copy link
Collaborator

This PR aims to handle all exceptions caused by reading a malformed class and handle those gracefully instead of throwing an error.

IDETECT-4924

@devmehtabd devmehtabd requested a review from Copilot November 21, 2025 20:33
@devmehtabd devmehtabd self-assigned this Nov 21, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances error handling for malformed class files by catching additional exception types that can occur during bytecode analysis and handling them gracefully instead of propagating errors.

Key Changes:

  • Extended exception handling to catch IllegalArgumentException in addition to StringIndexOutOfBoundsException when processing malformed method descriptors
  • Added comprehensive exception handling for various malformed class structure errors (IndexOutOfBoundsException, ClassFormatError, NegativeArraySizeException, OutOfMemoryError)
  • Modified error recovery to return Object.class type instead of re-attempting to parse the malformed descriptor

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
ClassMethodReferenceVisitor.java Extended catch block to handle IllegalArgumentException and changed error recovery to return Object.class type
MethodUseAnalyzer.java Added catch block for multiple exception types that can occur when reading malformed classes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

} else {
throw e;
}
} catch (IndexOutOfBoundsException | ClassFormatError | NegativeArraySizeException | OutOfMemoryError e) {
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

Catching OutOfMemoryError is generally not recommended as it indicates a serious JVM state that may prevent proper error handling or cleanup. OOM errors should typically be allowed to propagate so the application can fail-fast. If you must catch it, ensure that the error handling code itself doesn't allocate memory, and consider whether logging/storing the error in brokenFiles could succeed in an OOM condition.

Suggested change
} catch (IndexOutOfBoundsException | ClassFormatError | NegativeArraySizeException | OutOfMemoryError e) {
} catch (IndexOutOfBoundsException | ClassFormatError | NegativeArraySizeException e) {

Copilot uses AI. Check for mistakes.
@devmehtabd devmehtabd merged commit c3a7241 into master Dec 1, 2025
1 check passed
@devmehtabd devmehtabd deleted the dev/devm/handle-exceptions branch December 1, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants