[
https://issues.apache.org/jira/browse/SSHD-663?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
sirati97 updated SSHD-663:
--------------------------
Description:
I do not know whether 1.3.0 is affected.
in org.apache.sshd.common.file.util.ImmutableList.subList() the if criteria is
wrong:
wrong code:
{code:java}
@Override
public ImmutableList<T> subList(int fromIndex, int toIndex) {
if (fromIndex == from && toIndex == to) {
return this;
}
return new ImmutableList<>(data, from + fromIndex, from + toIndex);
}
{code}
should be:
{code:java}
@Override
public ImmutableList<T> subList(int fromIndex, int toIndex) {
if (fromIndex == 0 && from+toIndex == to) {
return this;
}
return new ImmutableList<>(data, from + fromIndex, from + toIndex);
}
{code}
Edit:
[~lgoldstein] proposed that i could contribute to the project and write a test
unit. Sadly i don't have enough time right now.
Anyway i wrote this test unit:
{code:java}
public class ImmutableListSubListTest {
@Test
public void start() {
String[] names = new String[] {"Name1","Name2","Name3","Name4","Name5"
,"Name6","Name7","Name8","Name9","Name10"};
ImmutableList<String> list1 = new ImmutableList<String>(names, 1 ,
names.length);
/*this should not work anyway, as you would move of of the bounds of
the parent list
But that's not checked
*/
ImmutableList<String> list2 = list1.subList(1 , names.length);
assertFalse("List1 and List2 should describe different lists, but they
are equal", list1 == list2);
ImmutableList<String> list3 = list1.subList(0, list1.size());
assertTrue("List1 and List3 should be the same instance as they are
immutable and have the same values, but they aren't.", list1 == list3);
}
}
{code}
It only runs with my fix.
was:
I do not know whether 1.3.0 is affected.
in org.apache.sshd.common.file.util.ImmutableList.subList() the if criteria is
wrong:
wrong code:
{code:java}
@Override
public ImmutableList<T> subList(int fromIndex, int toIndex) {
if (fromIndex == from && toIndex == to) {
return this;
}
return new ImmutableList<>(data, from + fromIndex, from + toIndex);
}
{code}
should be:
{code:java}
@Override
public ImmutableList<T> subList(int fromIndex, int toIndex) {
if (fromIndex == 0 && from+toIndex == to) {
return this;
}
return new ImmutableList<>(data, from + fromIndex, from + toIndex);
}
{code}
Edit:
> Wrong if criteria in org.apache.sshd.common.file.util.ImmutableList.subList()
> -----------------------------------------------------------------------------
>
> Key: SSHD-663
> URL: https://issues.apache.org/jira/browse/SSHD-663
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 1.1.0, 1.1.1, 1.2.0
> Reporter: sirati97
> Assignee: Goldstein Lyor
> Priority: Minor
> Labels: easyfix, newbie
> Original Estimate: 2m
> Remaining Estimate: 2m
>
> I do not know whether 1.3.0 is affected.
> in org.apache.sshd.common.file.util.ImmutableList.subList() the if criteria
> is wrong:
> wrong code:
> {code:java}
> @Override
> public ImmutableList<T> subList(int fromIndex, int toIndex) {
> if (fromIndex == from && toIndex == to) {
> return this;
> }
> return new ImmutableList<>(data, from + fromIndex, from + toIndex);
> }
> {code}
> should be:
> {code:java}
> @Override
> public ImmutableList<T> subList(int fromIndex, int toIndex) {
> if (fromIndex == 0 && from+toIndex == to) {
> return this;
> }
> return new ImmutableList<>(data, from + fromIndex, from + toIndex);
> }
> {code}
> Edit:
> [~lgoldstein] proposed that i could contribute to the project and write a
> test unit. Sadly i don't have enough time right now.
> Anyway i wrote this test unit:
> {code:java}
> public class ImmutableListSubListTest {
> @Test
> public void start() {
> String[] names = new String[] {"Name1","Name2","Name3","Name4","Name5"
>
> ,"Name6","Name7","Name8","Name9","Name10"};
> ImmutableList<String> list1 = new ImmutableList<String>(names, 1 ,
> names.length);
> /*this should not work anyway, as you would move of of the bounds of
> the parent list
> But that's not checked
> */
> ImmutableList<String> list2 = list1.subList(1 , names.length);
> assertFalse("List1 and List2 should describe different lists, but
> they are equal", list1 == list2);
> ImmutableList<String> list3 = list1.subList(0, list1.size());
> assertTrue("List1 and List3 should be the same instance as they are
> immutable and have the same values, but they aren't.", list1 == list3);
> }
> }
> {code}
> It only runs with my fix.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)