
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
40 lines
1.0 KiB
Plaintext
40 lines
1.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
A hardcoded file path is a guarantee that eventually the program will fail. It may happen because the paths on the target machine changed or because the application was deployed on an OS other than the one on which it was developed. After all, not every OS has a "C:" drive, just has not every OS has a "/home" directory.
|
|
|
|
|
|
This rule checks for hardcoded, absolute paths in ``++Files++`` and all types of input and output streams.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
public void readProperties() {
|
|
File in = new File("C:/myappdir/app.properties"); // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
public void readProperties(String path) {
|
|
File in = new File(path + "app.properties");
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== duplicates: S1075
|
|
|
|
=== on 10 Oct 2014, 14:35:48 Freddy Mallet wrote:
|
|
If my feeling is correct @Ann, this rule is duplicated by RSPEC-1075. Perhaps we should merge the two into one.
|
|
|
|
endif::env-github,rspecator-view[]
|