MINOR: Include the inner exception stack trace when re-throwing an exception#12229
MINOR: Include the inner exception stack trace when re-throwing an exception#12229ijuma merged 3 commits intoapache:trunkfrom
Conversation
|
@dengziming @hachikuji kindly review. Reviewer(s) please note that all tests failing for this CI are known to be flaky and are not related to this code change. Test 1 - testListenerConnectionRateLimitWhenActualRateAboveLimit - fix is pending PR review #12045 Test 2 - testTopicIdUpgradeAfterReassigningPartitions - fix is pending PR review #11687 Test 3 - testSnapshotOnlyAfterConfiguredMinBytes - (possible) fix is pending PR review #12224 Test 4 - Created a ticket at https://issues.apache.org/jira/browse/KAFKA-13951 |
10eeee8 to
da8cca4
Compare
|
@hachikuji Please review. This should be a small one. |
dengziming
left a comment
There was a problem hiding this comment.
Can this kind of problem be caught by spotbugs? manual checking is error prone.
Agreed @dengziming but unfortunately spotbugs isn't catching such errors. |
|
@mimaison perhaps you may want to look into this? This already has 2 approvals from non-committers. |
There was a problem hiding this comment.
Have we checked that we're not introducing a security vulnerability in these security classes by including the original exception?
There was a problem hiding this comment.
UnsupportedEncodingException is thrown for 2 cases and in either of the two cases, the string being encoded is not printed in the exception message and hence, we don't leak any message information using the exception.
Case 1: for UnsupportedCharsetException in which case, only charset is printed in the string as per the implementation as below:
public class UnsupportedCharsetException
extends IllegalArgumentException
{
private static final long serialVersionUID = 1490765524727386367L;
private String charsetName;
/**
* Constructs an instance of this class.
*
* @param charsetName
* The name of the unsupported charset
*/
public UnsupportedCharsetException(String charsetName) {
super(String.valueOf(charsetName));
this.charsetName = charsetName;
}
/**
* Retrieves the name of the unsupported charset.
*
* @return The name of the unsupported charset
*/
public String getCharsetName() {
return charsetName;
}
}
Case 2: for IllegalCharsetNameException which again, just prints the name of the charset. See implementation as below:
public class IllegalCharsetNameException
extends IllegalArgumentException
{
private static final long serialVersionUID = 1457525358470002989L;
private String charsetName;
/**
* Constructs an instance of this class.
*
* @param charsetName
* The illegal charset name
*/
public IllegalCharsetNameException(String charsetName) {
super(String.valueOf(charsetName));
this.charsetName = charsetName;
}
/**
* Retrieves the illegal charset name.
*
* @return The illegal charset name
*/
public String getCharsetName() {
return charsetName;
}
}
Is there any other security risk that you are alluding to here? Adding the stack trace is beneficial here to quickly determine whether the failure is due to case 1 or case 2.
There was a problem hiding this comment.
Thanks for the explanation @divijvaidya , yes, I checked and confirmed it only output the charset name. So it's safe. @ijuma , any concern/comments here?
clients/src/main/java/org/apache/kafka/common/record/DefaultRecordBatch.java
Outdated
Show resolved
Hide resolved
clients/src/main/java/org/apache/kafka/common/protocol/types/CompactArrayOf.java
Outdated
Show resolved
Hide resolved
|
@ijuma I have addressed your comments. This is ready for your review (pending test run). |
mdedetrich
left a comment
There was a problem hiding this comment.
These changes seem good for me
3c82b83 to
bc87930
Compare
|
@tombentley requesting code review bandwidth from you here. We already have 3 non-committer approvals on this one. |
showuon
left a comment
There was a problem hiding this comment.
LGTM! Thanks for the improvement.
There was a problem hiding this comment.
Thanks for the explanation @divijvaidya , yes, I checked and confirmed it only output the charset name. So it's safe. @ijuma , any concern/comments here?
bc87930 to
b5280b5
Compare
|
Rebased with the latest |
|
I'm going to merge this PR this week if there's no more comments. Thanks. |
clients/src/main/java/org/apache/kafka/common/protocol/types/TaggedFields.java
Outdated
Show resolved
Hide resolved
…master * apache-github/trunk: (23 commits) MINOR: Include the inner exception stack trace when re-throwing an exception (apache#12229) MINOR: Fix docs to state that sendfile implemented in `TransferableRecords` instead of `MessageSet` (apache#13109) Update ProducerConfig.java (apache#13115) KAFKA-14618; Fix off by one error in snapshot id (apache#13108) KAFKA-13709 (follow-up): Avoid mention of 'exactly-once delivery' or 'delivery guarantees' in Connect (apache#13106) KAFKA-14367; Add `TxnOffsetCommit` to the new `GroupCoordinator` interface (apache#12901) KAFKA-14568: Move FetchDataInfo and related to storage module (apache#13085) KAFKA-14612: Make sure to write a new topics ConfigRecords to metadata log iff the topic is created (apache#13104) KAFKA-14601: Improve exception handling in KafkaEventQueue apache#13089 KAFKA-14367; Add `OffsetCommit` to the new `GroupCoordinator` interface (apache#12886) KAFKA-14530: Check state updater more often (apache#13017) KAFKA-14304 Use boolean for ZK migrating brokers in RPC/record (apache#13103) KAFKA-14003 Kafka Streams JUnit4 to JUnit5 migration part 2 (apache#12301) KAFKA-14607: Move Scheduler/KafkaScheduler to server-common (apache#13092) KAFKA-14367; Add `OffsetFetch` to the new `GroupCoordinator` interface (apache#12870) KAFKA-14557; Lock metadata log dir (apache#13058) MINOR: Implement toString method for TopicAssignment and PartitionAssignment (apache#13101) KAFKA-12558: Do not prematurely mutate internal partition state in Mirror Maker 2 (apache#11818) KAFKA-14540: Fix DataOutputStreamWritable#writeByteBuffer (apache#13032) KAFKA-14600: Reduce flakiness in ProducerIdExpirationTest (apache#13087) ...
…ception (apache#12229) While wrapping the caught exception into a custom one, information about the caught exception is being lost, including information about the stack trace of the exception. When re-throwing an exception, we either include the original exception or the relevant information is added to the exception message. Reviewers: Ismael Juma <ismael@juma.me.uk>, Luke Chen <showuon@gmail.com>, dengziming <dengziming1993@gmail.com>, Matthew de Detrich <mdedetrich@gmail.com>
Problem:
While wrapping the caught exception into a custom one, information about the caught exception is being lost, including information about the stack trace of the exception.
Change
When re-throwing an exception, we make sure to include the stack trace. Otherwise pertinent debug information is lost.