Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[bug] System properties are only read if configuration file exists in class path #538

Closed
mriegler opened this issue Jul 22, 2024 · 3 comments

Comments

@mriegler
Copy link

Actual behaviour

Configuration via system properties is ignored as long as there is no "simplejavamail.properties" file in the class path.

Expected behaviour

Configuration via system properties is possible, even without a properties file.

Why it happens

This is because the ConfigLoader loadProperties that gets called in the static init block does NOT call readProperties. readProperties is where the system properties are used if set.

The loadProperties variant for InputStream does call readProperties, but is itself only called if the loadProperties for String finds a file on the class path.

Ergo to enable system properties you need to add a file to the class path.

How to reproduce

  • Use a basic builder, with no explicit optional settings, letting defaults happen
  • set a system property (for example simplejavamail.defaults.verifyserveridentity) to any valid, non-default value (e.g. false)
  • Check the setting in the Config of the Mailer the Builder built. In this example, OperationConfig isVerifyingIdentity should be false, but is true
  • add an empty "simplejavamail.properties" file to the classpath
  • Check the setting again. This time, it will have the correct value
@bbottema
Copy link
Owner

Thank you for your thorough report. I'm am currently out of the country for vacation and will look into this once I come back. Stay tuned!

@mriegler
Copy link
Author

mriegler commented Jul 23, 2024

I made a simple repro. Just run the test.sh (or read it)
simple-mail-repro.zip

Output is:

!!!!! Running without empty properties file !!!!
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
Verifying server identity from operational config: true
Verifying server identity from system prop: false

!!!!! Running with empty properties file !!!!!
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
Verifying server identity from operational config: false
Verifying server identity from system prop: false

bbottema pushed a commit that referenced this issue Sep 26, 2024
…, in the absence of a properties file (also env properties were loading incorrectly)
@bbottema bbottema changed the title System properties are only read if configuration file exists in class path [bug] System properties are only read if configuration file exists in class path Sep 26, 2024
bbottema pushed a commit that referenced this issue Sep 26, 2024
@bbottema bbottema added this to the 8.12.0 milestone Sep 26, 2024
@bbottema
Copy link
Owner

Fix released in v8.12.0.

bbottema pushed a commit that referenced this issue Oct 1, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants