-
Notifications
You must be signed in to change notification settings - Fork 66
Design improvements for FileSupplier.java #47
Comments
@sina-golesorkhi thanks for reporting the problem, we will discuss this problem in the team. First thing we will do, is to improve documentation. |
Hello everybody, I am working a small library that can be used for testing purposes. Basically I will create a @rule that can be integrated in an JUnit Test for creating at test execution time all required dependencies. Please have a little bit of more patience. Best regards, |
@sina-golesorkhi I like the idea of providing configurable properties via constructor or setter, but to be backwards-compatible and easy-to-use, we should populate these attributes from the environment. I would also suggest a fail-fast approach: A bad configuration should immediately throw a runtime exception. |
@harti2006 I'm not quite getting why providing a configuration from outside and doing inversion of control would add complexity to the library. Actually by providing those options you are telling your client in compile time what you do need (specially with the constructor). If this was an optional configuration I could follow your argument but right now the library is throwing an exception which is logged but swallowed. To me if a code needs a configuration from me it should tell me in the compile that what is needed and reading stuff statically from a central place (e.g. System) is generally a bad idea because you are hiding it from the client thought that you want him provide you with that. Regarding the fail-fast: As the client I would be happy to have that but such that this exception is bubbled up through the whole stack so that the client also gets the exception, though as I said in the previous paragraph by that time (runtime) the client wouldn't also be that much happy because the API didn't tell him (in compile time) that this exception is going to be thrown if one specific property is not configured/provided. |
because of the code you used in your comment. If you are using Spring-Boot, are you aware of Spring-Boot support for 'tokens'? It does not help to solve this concrete issue, but you don't have to write such custom-configurations as above and 'AccessTokens' will be available as injectable bean. |
@jbellmann I was not aware of this other project. Thank you for naming it I will have a look at it but as you also mentioned it is out of the scope of this issue because this issue is addressing a design improvement regarding this code base and one client might not want yet another dependency to another library;) |
@sina-golesorkhi @jbellmann @duergner @harti2006 @midumitrescu Hey, can we close this issue? It dates back to April 2016. Or: We could add labels to suggest "enhancement" or "Help wanted" or both. Your call. |
Wouldn't close it - but |
@jbellmann and me were thinking about fixing the issue with the mandatory environment variable, to prepare the 1.0.0 version of this library. |
What's the plan exactly? Nullable constructor parameter that fallsback to environment variable? |
I'm not sure. There are some cases (fixed test access tokens, or the test case above), where people don't want to worry about files and a credentials_dir at all. We need to provide an easy (and documented way) to turn the entire feature off. |
I assume we are using semantic versioning, right? Since we are still at |
What about a constructor which does exactly this, i.e. turn off the feature? Should be the most obvious approach, right? |
No "CREDENTIALS_DIR" exception if it is not configured.
I've created PR with one of the solutions. |
But that does not solve the underlying "problem" in cases we don't want to rely on |
@duergner Yes. It solves the problem when you want to use If we don't want to rely on |
I just wanted to rephrase the issue that I saw a in my code as the client of this library that lead to create this ticket. There is a magic happening in this code which is the access to |
@sina-golesorkhi do you think the proposal regarding having two constructors where one has the explicit mentioning and the other falling back to the current behaviour would make sense? We would not break backward compatibility (we could mark the one without arguments as |
@duergner sure. That would be the best option :) |
@duergner I was thinking that |
Imagine that you have a class like following:
And the following unit test:
The test will pass but still you will get an exception as following.
For the client code StupsOAuth2RestBean class there is no way of knowing about this missing configuration from outside and without looking into the source code I could not figure out that I have to configure environment variable because on line 51 and 55 of the FileSupplier.java this is read as env variable.
So my suggestions would be to document it so that it becomes more clear what this class is needing or the Java solution instead would be to read this value from outside (IoC) either by constructor or setters instead of static call to System class so that the client code knows about this and is forced to provide this in the compile time instead of reading from system environment (even this option can be provided if you want to read and write stuff in a static way using system environments).
The text was updated successfully, but these errors were encountered: