Skip to content
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

isValidImageFilename throws java.lang.IllegalArgumentException #596

Open
annguyen1291 opened this issue Sep 9, 2023 · 0 comments
Open
Assignees
Labels
bug Something isn't working
Milestone

Comments

@annguyen1291
Copy link

annguyen1291 commented Sep 9, 2023

In API/src/main/java/org/sikuli/script/Image.java, there is this method

public static boolean isValidImageFilename(String fname) {
    String validEndings = ".png.jpg.jpeg";
    String ending = FilenameUtils.getExtension(fname);
    return !ending.isEmpty() && validEndings.contains(ending.toLowerCase());
}

If the fname contains any forbidden characters (e.g. colon for Windows), the method will throw IllegalArgumentException but there is nothing to catch it. This issue affects commonly used methods like wait, find, click, type, etc. You can reproduce the bug by simply add the follow codes anywhere.

wait("Account Number: ")

I would propose to change the method to the follows.

public static boolean isValidImageFilename(String fname) {
    String validEndings = ".png.jpg.jpeg";
    String ending = "";
    try {
        ending = FilenameUtils.getExtension(fname);
    } catch(IllegalArgumentException e) {
        return false;
    }
    return !ending.isEmpty() && validEndings.contains(ending.toLowerCase());
}

I have created a pull request to fix the issue.
#597

Here is an example of the error log.

PS C:\Users\anguyen\tests.desktop> mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< SilverLake.SilverLakeTest:desktop >------------------
[INFO] Building desktop 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- clean:3.2.0:clean (default-clean) @ desktop ---
[INFO] Deleting C:\Users\anguyen\tests.desktop\target
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ desktop ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\anguyen\tests.desktop\src\main\resources
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ desktop ---
[INFO] No sources to compile
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ desktop ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 5 resources from src\test\resources to target\test-classes
[INFO]
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ desktop ---
[INFO] Changes detected - recompiling the module! :source
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 15 source files with javac [debug target 17] to target\test-classes
[INFO]
[INFO] --- surefire:3.1.2:test (default-test) @ desktop ---
[INFO] Using auto detected provider org.apache.maven.surefire.testng.TestNGProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
[error] Mouse: not useable (blocked)
Sep 08, 2023 1:35:36 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: OSS
[log] CLICK on L[61,121]@S(0) (555 msec)
[log] CLICK on L[224,241]@S(0) (549 msec)
[log] CLICK on L[695,230]@S(0) (548 msec)
[log]  TYPE "222600"
[error] Mouse.move(): Mouse not useable (blocked)
java.lang.IllegalArgumentException: NTFS ADS separator (':') in file name is forbidden.
        at org.apache.commons.io.FilenameUtils.indexOfExtension(FilenameUtils.java:737)
        at org.apache.commons.io.FilenameUtils.getExtension(FilenameUtils.java:1057)
        at org.sikuli.script.Image.isValidImageFilename(Image.java:751)
        at org.sikuli.script.Image.createImageValidate(Image.java:737)
        at org.sikuli.script.Image.create(Image.java:662)
        at org.sikuli.script.Element.getImageFromTarget(Element.java:378)
        at org.sikuli.script.Region$RepeatableFind.<init>(Region.java:3040)
        at org.sikuli.script.Region.wait(Region.java:2181)
        at org.sikuli.script.Region.waitText(Region.java:2698)
        at Pages.SikulixBasePage.waitText(SikulixBasePage.java:26)
        at Pages.SilverLake.GeneralLedgerInquiryPage.assertGLDownload(GeneralLedgerInquiryPage.java:62)
        at Tests.SilverLake.GeneralLedgerInquiryTest.createGLDownload(GeneralLedgerInquiryTest.java:14)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
        at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:664)
        at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:227)
        at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
        at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:957)
        at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:200)
        at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
        at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at org.testng.TestRunner.privateRun(TestRunner.java:848)
        at org.testng.TestRunner.run(TestRunner.java:621)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:443)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:437)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:397)
        at org.testng.SuiteRunner.run(SuiteRunner.java:336)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1280)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1200)
        at org.testng.TestNG.runSuites(TestNG.java:1114)
        at org.testng.TestNG.run(TestNG.java:1082)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:308)
        at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:71)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:113)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
        at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 80.86 s <<< FAILURE! -- in TestSuite
[ERROR] Tests.SilverLake.GeneralLedgerInquiryTest.createGLDownload -- Time elapsed: 64.19 s <<< FAILURE!
java.lang.NullPointerException: Cannot invoke "org.sikuli.script.Match.grow()" because the return value of "Pages.SilverLake.GeneralLedgerInquiryPage.waitText(String, int)" is null
        at Pages.SilverLake.GeneralLedgerInquiryPage.assertGLDownload(GeneralLedgerInquiryPage.java:62)
        at Tests.SilverLake.GeneralLedgerInquiryTest.createGLDownload(GeneralLedgerInquiryTest.java:14)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
        at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:664)
        at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:227)
        at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
        at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:957)
        at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:200)
        at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
        at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at org.testng.TestRunner.privateRun(TestRunner.java:848)
        at org.testng.TestRunner.run(TestRunner.java:621)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:443)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:437)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:397)
        at org.testng.SuiteRunner.run(SuiteRunner.java:336)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1280)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1200)
        at org.testng.TestNG.runSuites(TestNG.java:1114)
        at org.testng.TestNG.run(TestNG.java:1082)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:308)
        at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:71)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:113)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
        at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   GeneralLedgerInquiryTest.createGLDownload:14 » NullPointer Cannot invoke "org.sikuli.script.Match.grow()" because the return value of "Pages.SilverLake.GeneralLedgerInquiryPage.waitText(String, int)" is null
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:26 min
[INFO] Finished at: 2023-09-08T13:36:41-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.1.2:test (default-test) on project desktop: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\anguyen\tests.desktop\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
PS C:\Users\anguyen\tests.desktop>
@RaiMan RaiMan self-assigned this Feb 11, 2024
@RaiMan RaiMan added the bug Something isn't working label Feb 11, 2024
@RaiMan RaiMan added this to the 2.0.6 milestone Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants