Skip to content

Commit

Permalink
Fix possible ArrayStoreException in stream (#701)
Browse files Browse the repository at this point in the history
* Fix possible ArrayStoreException in stream

* Fix possible ArrayStoreException in stream. Add regression test
  • Loading branch information
turbanoff authored Sep 15, 2021
1 parent b14c437 commit 9ca636f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion terminal/src/main/java/org/jline/utils/InfoCmp.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public enum Capability {
public String[] getNames() {
return getCapabilitiesByName().entrySet().stream()
.filter(e -> e.getValue() == this)
.map(Map.Entry::getValue)
.map(Map.Entry::getKey)
.toArray(String[]::new);
}

Expand Down
9 changes: 7 additions & 2 deletions terminal/src/test/java/org/jline/utils/InfoCmpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystems;
Expand All @@ -29,8 +28,8 @@
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand All @@ -52,6 +51,12 @@ public void testInfoCmp() {
assertTrue(strings.containsKey(Capability.byName("acsc")));
}

@Test
public void testGetNames() {
String[] result = Capability.bit_image_entwining.getNames();
assertArrayEquals(new String[]{"bit_image_entwining", "bitwin"}, result);
}

@Test
public void testInfoCmpWithHexa() {
Set<Capability> bools = new HashSet<>();
Expand Down

0 comments on commit 9ca636f

Please sign in to comment.