bmarwell commented on a change in pull request #288:
URL: https://github.com/apache/shiro/pull/288#discussion_r599716165



##########
File path: 
core/src/main/java/org/apache/shiro/realm/text/TextConfigurationRealm.java
##########
@@ -211,9 +215,15 @@ protected void processUserDefinitions(Map<String, String> 
userDefs) {
 
     protected static Set<String> toLines(String s) {
         LinkedHashSet<String> set = new LinkedHashSet<String>();
-        Scanner scanner = new Scanner(s);
-        while (scanner.hasNextLine()) {
-            set.add(scanner.nextLine());
+        try (Scanner scanner = new Scanner(s)) {
+            while (scanner.hasNextLine()) {
+                set.add(scanner.nextLine());
+            }
+        } catch (Exception e) {
+            if (log.isWarnEnabled()) {
+                String msg = "Unable to fetch next line, Scanner stream 
corrupted.";
+                log.warn(msg, e);
+            }

Review comment:
       Do not catch a generic exception. In this case, do not catch anything at 
all. We would want the Exception to promote here, otherwise the behaviour would 
change.

##########
File path: 
core/src/test/java/org/apache/shiro/realm/text/TextConfigurationRealmTest.java
##########
@@ -247,6 +249,21 @@ public void run() {
         assertTrue("account doesn't exist when it should", 
realm.accountExists("user1"));
         testThread.test();
     }
+    
+    /*
+     * Test that scanner reads next line
+     */
+    @Test
+    public void testScannerHasNextLine() {
+        realm = new TestRealm() {
+            public void test(Thread runnable) throws InterruptedException {
+                Scanner scanner = new Scanner("Scanner\nTest\n");
+                Assert.assertNotNull(scanner);
+                assertEquals("Scanner", scanner.nextLine());
+                assertEquals("Test", scanner.nextLine());

Review comment:
       You are testing `java.util.Scanner`, not `TextConfigurationRealm` you 
modified. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to