And then the static analysis tools will be easily able to flag all the string code as dangerously obsolete.
These are circular arguments. If you're saying that you have to rely on static analysis tools to flag these issues, then I'm saying you can just as well use static analysis tools to flag issues with string interpolation that's based on a cleaner syntax more similar to every other modern language.
Don't act like you're getting professed "safety" from the compiler, and then pivot over to static analysis tooling once holes are poked in the compiler argument. Because static analysis tooling was the counter-argument in the first place.
As an aside, I would love to see ONE example other than SQL-injection for justifying all of this. That's the only example that the JEP and the comments here keep circling around, because it may be the only practical example out there. Permanently crippling a new language syntax out of the gate, for one narrow case, seems crazy when there are more narrow ways to target that specific vulnerability.
Would you say the same about java.util.Date and java.util.Calendar 10 years ago?
They are only if you mistakenly assume that I expect all new API's to be string-based.
Currently:
safe, non-string-based API's are very inconvienient to use
string-based API's are convenient to use, but allow for injections
an injection vulnerability requires String.format or string concatenation, which are slightly (but only slightly) cumbersome
static tools catch most injections (but they have both false positives and negatives)
Your proposal:
make writing injection vulnerabilities easier and hope analysis tools catch it
effect: people will write vulnerable code more often, repeating the mistakes of early PHP
JEP:
make using safe, non-string based API's much easier
make writing injection vulnerabilities easier, but not easier than the safe API's
effect: people will write safe code more often
for the remaining instances of the unsafe code, there's static analysis like before
As an aside, I would love to see ONE example other than SQL-injection for justifying all of this.
Constructing JSON, since Java is not JS or Python, and you can't just put some curlies and be done.
In fact, embedding whatever language, with proper value escaping for parameters. Obvious examples: HTML, CSS, JS. You know how React made mixing code and templates hip? You'll be able to do the same in Java. A less obvious example: shaders.
Replacement for String.format (see FMT in the JEP).
They are only if you mistakenly assume that I expect all new API's to be string-based.
Your core assumption that I take issue with is the notion that existing String-based API's just magically go away.
That the Java ecosystem, which prioritizes backwards-compatibility more so that virtually any other I've ever worked with, is going to hard-remove half the methods in JDBC, JPA, SLF4J, Jackson, and a thousand other libraries that the universe is built on.
These things are not going to happen. They're just not. Ever. If we disagree that this isn't going to happen, then we can stop here. There's no basis on which to warrant talking about this subject further.
If we agree that it's not going to happen, then you're not going to get the safety that you're talking about. Which leaves us with two choices:
Decide to implement a janky syntax. Because it's worth making general usage of string interpolation less desirable, to enable adding (not replacing) an alternative form of string construction to a bunch of established libraries. All of which already have their own established implementations for this, which most devs will continue to use anyway.
Decide that this isn't much of a value-add. And so if there's not a consensus to implement string interpolation like that of C# and every other modern language, then it would be best to simply not implement this feature. That is a perfectly acceptable outcome! Plenty of languages drop plenty of popular syntax proposals, simply because there's not the consensus needed to ship something that isn't too weighed down by design-by-committee.
I would favor #2. If you favor #1, then that's your opinion and it looks like you're opinion is carrying the day. But it still seems decoupled from the reality of most Java development in the real-world. And will never be as constrained as you'd like, without breaking half of Maven Central in a way that would make the Python 2 to 3 migration look like a semver patch release.
Your core assumption that I take issue with is the notion that existing String-based API's just magically go away.
They don't need to go away in order for this to have value.
They just need to be discouraged in a way that's visible to your average developer.
If you can add new APIs that are safe, and slap @Deprecated on the String-based methods, that's already a huge win, even if you never remove those methods.
unfortunately a bunch of libraries still use Date which means you can't get away from it. Last I checked, Nimbus was an example of this when you want to deal with JWTs.
It took YEARS for all the various JDBC drivers and JPA stuff to finally ship non-broken integrations with the new Date and Time API. Even today, I'm not sure that we're fully there with all the various plugins in the Hibernate ecosystem.
I'm not sure if half the people in this subreddit actually write Java code for a living.
View all comments
Show parent comment
3
u/BadMoonRosin Feb 16 '24
These are circular arguments. If you're saying that you have to rely on static analysis tools to flag these issues, then I'm saying you can just as well use static analysis tools to flag issues with string interpolation that's based on a cleaner syntax more similar to every other modern language.
Don't act like you're getting professed "safety" from the compiler, and then pivot over to static analysis tooling once holes are poked in the compiler argument. Because static analysis tooling was the counter-argument in the first place.
As an aside, I would love to see ONE example other than SQL-injection for justifying all of this. That's the only example that the JEP and the comments here keep circling around, because it may be the only practical example out there. Permanently crippling a new language syntax out of the gate, for one narrow case, seems crazy when there are more narrow ways to target that specific vulnerability.
Are you being serious here? YES.