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

Update WinProcess.java #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

senderic
Copy link

@senderic senderic commented Jun 7, 2018

Using getCommandLine() in the toString() function to ensure that the commandline String variable is set. The getCommandLine() function will internally have it parsed if it is currently null.

Using `getCommandLine()` in the `toString()` function to ensure that the `commandline` String variable is set. The `getCommandLine()` function will internally have it parsed if it is currently null.
Fixing line 27 which somehow got altered in my first commit. My bad not picking up on this on that first commit.
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intentional to avoid excessive load when the values are not available. What is a use-case for it?

@senderic
Copy link
Author

senderic commented Jun 8, 2018

When I tried to print the contents of my WinProcess object, I was getting a null at the end of the toString. I realized it was because the toString function relies of the variable being set, which only happens in the getter, not the constructor. So alternatively I think having the constructor create the object is fine as well.

@oleg-nenashev
Copy link
Member

Would if we replace null by a more explicit string like: "cmd line arguments have not been read yet" or so?

@senderic
Copy link
Author

senderic commented Jun 8, 2018

That certainly is better than null. I do wonder why would there be concern about excessive load for this parsing event in the toString. I'd think the user of your API would expect the command to be available to them. I did, which is what lead me to looking at the source code and making this pull request.

@oleg-nenashev
Copy link
Member

Retrieval of process command line is pretty heavy, because it has to read the Process headers.
toString() method was being used externally in logging (e.g. in https://github.com/jenkinsci/jenkins/blob/e18df1ffd3d53fe12f6dca75a264b3550d6e8e5f/core/src/main/java/hudson/util/ProcessTree.java before I cleaned it up), and I can imagine other such cases in external usages.

If API users need to get command line, there is a WinProcess#getCommandLine() method for it.

Anyway, I will update the string to make the message more clear

@oleg-nenashev oleg-nenashev self-assigned this Jun 23, 2018
@oleg-nenashev
Copy link
Member

Fix applied in bd2fa87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants