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

[core] Analysis cache fails with wildcard classpath entries #1477

Closed
ColColonCleaner opened this Issue Nov 20, 2018 · 5 comments

Comments

Projects
None yet
2 participants
@ColColonCleaner
Copy link

ColColonCleaner commented Nov 20, 2018

Affects PMD Version: 6.9.0

Rule: Runtime, no specific rule.

Description: We have a file path variable on the stack that ends with a * for wildcarding. For backwards compatibility reasons this cannot be removed. If I add the cacheLocation parameter to the pmd call with any path, absolute, relative, parameterized, etc, it throws the following error when running the PMD target:
c:\absolutepath\build.xml:1301: java.nio.file.InvalidPathException: Illegal char * at index 35: c:\wildcardingpath*
Adding that parameter appears to make PMD look at other variables on the stack that aren't directly provided to it.
We had this same issue with junit and javac but those targets allow the includeAntRuntime="false" parameter to forcibly tell them to ignore all other variables on the stack aside from what you pass into the target. This parameter for ignoring other variables doesn't appear to be allowed on PMD.

Running PMD through: [Ant]

I am running this through Java 11 64 bit on a windows 7 machine.

@adangel

This comment has been minimized.

Copy link
Member

adangel commented Nov 20, 2018

Hi, thanks for the report!

Could you copy your ant script (or at least the PMD part of it) here?

Just to make sure, I understand your problem: you are using the <cacheLocation>c:\wildcardingpath*</cacheLocation> and that causes a problem. Is c:\wilcardingpath* a valid path at all? How did you create it? The asterisk is usually expanded by a shell but here we have no shell to interpret the wildcard.

Please also note, that the cacheLocation should point to a specific file - if you use a wildcard, it is not unique anymore - we don't know, which file we should write to/read from if we are provided with multiple files (or in other words: the cacheLocation is given ambiguously...)

@ColColonCleaner

This comment has been minimized.

Copy link

ColColonCleaner commented Nov 20, 2018

This wildcarding path is not associated with PMD at all, it's just some path in another variable on the stack. According to the PMD docs there isn't a cacheLocation element on the pmd target, it's added as a parameter on the target. I just tried it the way you mentioned and the error "pmd doesn't support the nested 'cacheLocation' element" occured.
If I include the cacheLocation parameter the illegal char error occurs, if I do not include the cacheLocation parameter PMD runs as normal without caching.

Here ${env.DCSDIR}/${cache.file} translates to: c:\dev\workspace\181branch\wmd/pmdrules.cache
This file exists and is empty.

Github's system really hates XML huh. Linking a picture.
image

@ColColonCleaner

This comment has been minimized.

Copy link

ColColonCleaner commented Nov 20, 2018

Here is the Illegal character error. This path it mentions is not passed into PMD at all, it's just present in the ant environment at runtime, one of the paths we use for another product.
image

@adangel

This comment has been minimized.

Copy link
Member

adangel commented Nov 21, 2018

it's added as a parameter on the target. I just tried it the way you mentioned and the error "pmd
doesn't support the nested 'cacheLocation' element" occured.

Oh, yes. My bad.

The snippet from build.xml and the stacktrace help a lot, however:
It happens not when we try to read/write the cacheLocation file, but when we try to determine, whether the execution classpath or the auxclasspath has changed from the last run (therefore we compute a checksum over the classpath).

-> The problem is, that we obviously can't deal yet with a wildcard classpath entry.

Until this bug is fixed, the only workaround is, that you explicitly specify pmd.classpath without a wildcard.

One note to your PMD task configuration though:

For the auxclasspath element, you are using the same classpath as you use for executing PMD itself:

<auxClasspath>
    <path refid="pmd.classpath"/>
</auxClasspath>

You should actually use the classpath, that you are using for compiling your project. This means, the auxclasspath should contain all the jars that you need during compilation. This makes sure, that PMD has the same knowledge as the compiler does and can figure out the types of various statements.

@adangel adangel added the a:bug label Nov 21, 2018

@adangel adangel changed the title [Java] Ant cacheLocation parameter causes path exception when environment variable ending in * is present. [core] Analysis cache fails with wildcard classpath entries Nov 21, 2018

@adangel

This comment has been minimized.

Copy link
Member

adangel commented Nov 21, 2018

Or of course, can disable the cache:

<pmd ... noCache="true">
...

@adangel adangel self-assigned this Nov 25, 2018

@adangel adangel added this to the 6.10.0 milestone Nov 25, 2018

adangel added a commit to adangel/pmd that referenced this issue Nov 29, 2018

@adangel adangel added the has:pr label Nov 29, 2018

@adangel adangel closed this in #1489 Dec 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment