Bug 62127

Summary: CSV Data Set Config changes slash in filename path into backslash
Product: JMeter - Now in Github Reporter: Benny van Wijngaarden <benny>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: major CC: p.mouawad, toh2526
Priority: P2 Keywords: FixedInTrunk
Version: 4.0   
Target Milestone: JMETER_5.0   
Hardware: PC   
OS: All   
Attachments: Store filename as string not as a file

Description Benny van Wijngaarden 2018-02-23 07:29:21 UTC
The CSV Data Set Config element changes a '/' entered in the Filename field automically into a '\' when saving test plan.

Situation:
- Open a file with a CSV Data Set Config element
- Edit the path to contain e.g. testdata/myfile.csv
- Pressing Save will change the / into \

On Windows this still works, but when running the script on Jenkins this causes problems: the file cannot be found.

Tested and reproduced on:
OS: Windows 8 
LAF: Metal, Nimbus, Darcula
Comment 1 Benny van Wijngaarden 2018-02-23 08:21:38 UTC
Possible workaround: enclose the Filename path string in a BeanShell function. 
Example: ${__BeanShell("testdata/myfile.csv")}

This leaves the string untouched when the Test Plan is saved.
Comment 2 Philippe Mouawad 2018-02-23 08:42:27 UTC
Hello,
What is your java version ?
Also is it OpenJDK or Oracle ?

Thanks
Comment 3 Benny van Wijngaarden 2018-02-23 13:22:19 UTC
We use C:\Program Files (x86)\IBM\WebSphere\AppServer-85\java_1.8_64 to start JMeter
Comment 4 Philippe Mouawad 2018-02-23 13:25:20 UTC
Hello,
Can you try with last Oracle JDK 8 ?
Thanks
Comment 5 Benny van Wijngaarden 2018-02-23 13:50:17 UTC
I did, same behaviour
Comment 6 Felix Schumacher 2018-02-23 17:33:05 UTC
That behaviour is because of the File#getPath converts the path separators under Windows to backslashes. The File is used in FileEditor.
Comment 7 Felix Schumacher 2018-02-24 16:01:39 UTC
Created attachment 35741 [details]
Store filename as string not as a file

The FileEditor component is used to edit/select filenames. It currently stores the filename as a File. That is problematic as java will convert slashes (/) to backslashes (\) when running on Windows.

This patch will store the filenames as simple String instances. That way no conversion will be done by java, except when filenames get selected through a file chooser dialog. In that case the patch will convert the backslashes to slashes when run on Windows.
Comment 8 Felix Schumacher 2018-02-24 16:28:56 UTC
If this patch works, would it be sensible to remove the inner class SimpleFileEditor from FileEditor? It seems to have no function anymore (when the patch is applied).
Comment 9 Felix Schumacher 2018-02-24 17:02:16 UTC
Will be included in v4.1

@Benny, could you test the fix?

Date: Sat Feb 24 17:01:14 2018
New Revision: 1825265

URL: http://svn.apache.org/viewvc?rev=1825265&view=rev
Log:
Store filename as String instead of File in FileEditor.

This will prevent conversion of filenames from unix style path separators
to Windows style when used for example in CSV Data Set Config.

Bugzilla Id: 62127

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/FileEditor.java
    jmeter/trunk/xdocs/changes.xml
Comment 10 Benny van Wijngaarden 2018-02-26 09:54:03 UTC
Tested the fix: OK

I replaced ApacheJMeter_core.jar in the 4.0 release by the one from the nightly build of today. @Philippe or Felix, do you expect any problems doing this?
Comment 11 Felix Schumacher 2018-02-26 17:31:34 UTC
(In reply to Benny van Wijngaarden from comment #10)
> Tested the fix: OK
> 
> I replaced ApacheJMeter_core.jar in the 4.0 release by the one from the
> nightly build of today. @Philippe or Felix, do you expect any problems doing
> this?

What exactly do you mean by "this"? Do we expect problems when replacing the core jar or by the patch itself?

In case of the patch itself, I don't expect problems.

In case of replacing the jar, I think you might be safer replacing all jars (though if it works for you, it is probably OK for the nightly you chose).

As you confirmed that the problem is fixed, I will close this bug. Thanks for the report and the confirmation.
Comment 12 Benny van Wijngaarden 2018-02-27 12:06:00 UTC
Do you have any idea when version 4.1 will be released? I have to decide whether to rollout the snapshot version in my team or wait for the 4.1 release.
Comment 13 Felix Schumacher 2018-11-08 18:50:48 UTC
*** Bug 62715 has been marked as a duplicate of this bug. ***
Comment 14 The ASF infrastructure team 2022-09-24 20:38:12 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/4704