-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Ignite 28747 quick fix #13495
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
Open
EgorBaranovEnjoysTyping
wants to merge
13
commits into
apache:master
Choose a base branch
from
EgorBaranovEnjoysTyping:ignite-28747-quick-fix
base: master
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.
Open
Ignite 28747 quick fix #13495
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7c415f1
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE. Fix A…
EgorBaranovEnjoysTyping 30d0351
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE.
EgorBaranovEnjoysTyping d020d75
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE. Add s…
EgorBaranovEnjoysTyping 93a68b6
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE.
EgorBaranovEnjoysTyping 8398284
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE.
EgorBaranovEnjoysTyping cd4e38e
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE.
EgorBaranovEnjoysTyping b700b12
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE.
EgorBaranovEnjoysTyping c71d5d7
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE.
EgorBaranovEnjoysTyping bcc863a
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE.
EgorBaranovEnjoysTyping ad3875f
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE.
EgorBaranovEnjoysTyping 474147a
Update modules/commons/src/main/java/org/apache/ignite/internal/util/…
EgorBaranovEnjoysTyping 0cc9bee
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE.
EgorBaranovEnjoysTyping 475433a
IGNITE-28747 GridToStringBuilder#handleRecursion may cause NPE.
EgorBaranovEnjoysTyping 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
113 changes: 113 additions & 0 deletions
113
.../core/src/test/java/org/apache/ignite/internal/util/tostring/SBLimitedLengthSelfTest.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,113 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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 | ||
| * | ||
| * http://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. | ||
| */ | ||
|
|
||
| package org.apache.ignite.internal.util.tostring; | ||
|
|
||
| import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; | ||
| import org.apache.ignite.testframework.junits.common.GridCommonTest; | ||
| import org.junit.Test; | ||
|
|
||
| /** Test suite to ensure SBLimitedLength works by design */ | ||
| @GridCommonTest(group = "Utils") | ||
| public class SBLimitedLengthSelfTest extends GridCommonAbstractTest { | ||
| /** Ensure all append operations are working fine */ | ||
| @Test | ||
| public void testAppend() { | ||
| SBLimitedLength strBuilder = stringBuilder(5); | ||
| strBuilder.a(1); | ||
| assertEquals("1", strBuilder.toString()); | ||
| strBuilder.a(2L); | ||
| assertEquals("12", strBuilder.toString()); | ||
| strBuilder.a(3f); | ||
| assertEquals("123.0", strBuilder.toString()); | ||
| strBuilder.a(4d); | ||
| assertEquals("123.04.0", strBuilder.toString()); | ||
| strBuilder.a('5'); | ||
| assertEquals("123.04.05", strBuilder.toString()); | ||
| strBuilder.a(true); | ||
| assertEquals("123.04.05true", strBuilder.toString()); | ||
| Object obj = "6"; | ||
| strBuilder.a(obj); | ||
| assertEquals("123.04.05true6", strBuilder.toString()); | ||
| strBuilder.a("7"); | ||
| assertEquals("123.04.05true67", strBuilder.toString()); | ||
| strBuilder.a(new StringBuilder().append("8")); | ||
| assertEquals("123.04.05true678", strBuilder.toString()); | ||
| CharSequence charSeq = "9"; | ||
| strBuilder.a(charSeq); | ||
| assertEquals("123.04.05true6789", strBuilder.toString()); | ||
| strBuilder.a(charSeq, 0, 1); | ||
| assertEquals("123.04.05true67899", strBuilder.toString()); | ||
| } | ||
|
|
||
| /** */ | ||
| @Test | ||
| public void testDoesNotThrowNPEOnHeadOverflow() { | ||
| SBLimitedLength sbLimitedLength = new SBLimitedLength(256); | ||
| sbLimitedLength.initLimit(new SBLengthLimit()); | ||
| sbLimitedLength.a("a".repeat(7999)); | ||
| sbLimitedLength.i(7000, "asd"); | ||
| sbLimitedLength.a("a".repeat(10)); | ||
| String result = sbLimitedLength.toString(); | ||
| assertNotNull(result); | ||
| assertFalse(result.isEmpty()); | ||
| assertTrue(result.contains("asd")); | ||
| } | ||
|
|
||
| /** | ||
| * Test that simulates the NPE scenario from handleRecursion. | ||
| * When tail is null but overflowed() returns true, append operations should not throw NPE. | ||
| */ | ||
| @Test | ||
| public void testNPEProtectionWithNullTail() { | ||
| SBLimitedLength sb = new SBLimitedLength(256); | ||
| sb.initLimit(new SBLengthLimit()); | ||
| sb.a("a".repeat(8000)); | ||
| sb.i(0, "@0"); | ||
| sb.a("x"); | ||
| } | ||
|
|
||
| /** Ensure toString works as expected */ | ||
| @Test | ||
| public void testToString() { | ||
| SBLimitedLength strBuilder = stringBuilder(2); | ||
| strBuilder.a("ab"); | ||
| assertEquals("ab", strBuilder.toString()); | ||
| strBuilder.a("cd"); | ||
| assertEquals("abcd", strBuilder.toString()); | ||
| } | ||
|
|
||
| /** | ||
| * Get {@link SBLimitedLength} instance with specific head and tail length | ||
| * to simplify test cases | ||
| * @param headLength Head length. | ||
| */ | ||
| private SBLimitedLength stringBuilder(int headLength) { | ||
| SBLimitedLength sbLimitedLength = new SBLimitedLength(0); | ||
|
|
||
| sbLimitedLength.initLimit(new SBLengthLimit() { | ||
| @Override boolean overflowed(SBLimitedLength sb) { | ||
| return sb.impl().length() > headLength; | ||
| } | ||
| }); | ||
|
|
||
| return sbLimitedLength; | ||
|
EgorBaranovEnjoysTyping marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.