[ 
https://issues.apache.org/jira/browse/SOLR-18057?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18049954#comment-18049954
 ] 

David Smiley commented on SOLR-18057:
-------------------------------------

Gemini suggested the following CodeQL:
{noformat}
/**
 * @name Path.of with String argument
 * @kind problem
 * @problem.severity recommendation
 * @id java/path-of-string-check
 */

import java

from MethodAccess call, Method target
where
  // 1. Find the method definition
  call.getMethod() = target and
  target.hasName("of") and
  target.getDeclaringType().hasQualifiedName("java.nio.file", "Path") and

  // 2. Identify the first argument (index 0)
  // 3. Check if that argument's type is a String
  call.getArgument(0).getType().hasQualifiedName("java.lang", "String")

select call, "This call to Path.of uses a String as the first argument."
{noformat}

> Review Path.of for places where Path.resolve should be used
> -----------------------------------------------------------
>
>                 Key: SOLR-18057
>                 URL: https://issues.apache.org/jira/browse/SOLR-18057
>             Project: Solr
>          Issue Type: Improvement
>            Reporter: Eric Pugh
>            Priority: Minor
>              Labels: newdev
>
> Plucked from discussion 
> [https://github.com/apache/solr/pull/3988#discussion_r2659300249]
>  
> Specifically in BinaryFieldTest we have:
>  
> | // Copy the custom schema for binary field tests|
> | String sourceConfDir = TEST_HOME() + "/collection1/conf";|
>  
> "If you look carefully at what's happening here (was before), this is sad. 
> TEST_HOME() returns a Path, which we toString via string concatenation to a 
> String representing a path, and then a line below we create a Path via 
> {{{}Path.of{}}}. Obviously we should instead be using the {{resolve}} method 
> on Path. The tell-tale sign of the problem is the usage of {{Path.of}} which 
> we should ideally use sparingly (when we truly have a String input that can't 
> be a Path)."
>  
> This ticket would be to look at places we are using Path.of on a string and 
> see if we are doing some extra conversion steps instead of using a 
> Path.resolve.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to