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

Unset config properties: use default value or fail with a meaningful exception #10013

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zbynek
Copy link
Contributor

@zbynek zbynek commented Oct 18, 2024

Fixes #9885

Not quite sure about the usecase where the Joiner is actually used.

@zbynek zbynek marked this pull request as draft October 18, 2024 21:46
@zbynek zbynek marked this pull request as ready for review October 18, 2024 22:49
@@ -76,7 +77,14 @@ public void endVisit(JPermutationDependentValue x, Context ctx) {
private JExpression propertyValueExpression(JPermutationDependentValue x) {
List<String> propertyValues = props.getConfigurationProperties().getStrings(x.getRequestedValue());

String propertyValue = propertyValues.isEmpty() ? null : Joiner.on(",").join(propertyValues);
if (!propertyValues.isEmpty() && propertyValues.stream().allMatch(Objects::isNull)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I struggle with this distinction every time I try to get back into this code and clean it up - could you add a comment here explaining why we sometimes get [] and sometimes [null]? I think it is signalling (badly, incompletely) that this config property is only permitted to have a single value, but there is no distinction here between "multi-valued with one value" and "single valued and set", so I'm not sure why it matters... Also there is no distinction between "multivalued and unset" and "undefined key", which seems even more egregious.

At least if we keep that confusing behavior, a comment would help to clarify as to why we even do it this way.

if (x.getDefaultValueExpression() != null) {
return x.getDefaultValueExpression();
}
throw new InternalCompilerException("No default set for configuration property '"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to throw here? What about letting the value be null - that's what would happen for java if a system property was unset?

That said, this could also be a follow-up feature after the bug is fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From #9806 (comment) I assumed that defining a config property without a default is bad and should result in a build failure. That's also why I filed gwtproject/gwt-safehtml#31 . I'm OK with changing the behavior and returning null. @jnehlmeier thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is an internal compiler error I guess I just don't like it to happen under normal circumstances for a user who either
a) was expecting System.getProperty(name) to return null
b) forgot to pass a default as the second arg to Sysmte.getProperty
c) forgot to set the config property value

Any/all of those seem like a reasonable expectations to have - and you shouldn't be rewarded with an InternalCompilerException if you fail that. Plus, if you hit one ICE, that's the end of compilation, but we in theory could have several errors we could pick up here. ICE does have the advantage that it gives you very clear context about where the error happened - but we have the SourceInfo instance here and can log something helpful?

JsInteropRestrictionChecker is a pretty good example of "I need to log a fatal error for the developer to consume, and a stack trace will never help them figure it out".

If the user did make mistake A or B above, then logging an error will help them figure it out. C wouldn't be as helpful, but the text of the message can be clear that they just need to define a value in the .gwt.xml (or command line, -setProperty foo=bar).

throw new InternalCompilerException("No default set for configuration property '"
+ x.getRequestedValue() + "'");
}
String propertyValue = propertyValues.isEmpty() ? null : Joiner.on(",").skipNulls().join(propertyValues);
Copy link
Contributor

Choose a reason for hiding this comment

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

 /home/runner/work/gwt/gwt/gwt/dev/core/src/com/google/gwt/dev/jjs/impl/ResolvePermutationDependentValues.java:78:0: warning: Line is longer than 100 characters (found 105). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
/home/runner/work/gwt/gwt/gwt/dev/core/src/com/google/gwt/dev/jjs/impl/ResolvePermutationDependentValues.java:87:0: warning: Line is longer than 100 characters (found 111). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)

If I'm reading right the first is outside of your patch so ignore.

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.

Compiling with System.getProperty can throw NPE rather than useful error
2 participants