News for hackers. Stuff that matters.
Re:Java 24 by atomicnumber3 on Tuesday March 18, 2025 @10:38AM (#43399989)
SecurityManager dies not with a bang, but a whimper. The professor who taught a generally-misguided Java elective extolled the benefits of the security manager whenever he could. I was tremendously skeptical at the time. I'm inappropriately smug to have been proven right now, several decades later.

I really want structured concurrency out of preview!! I think it helps close one of the last gaps golang has over Java in the ease-of-concurrent-programming side of things. Go makes channels and waitgroups pretty easy. I think structured concurrency is a great side-step of those primitives by actually making the higher-level tasks you use those tools to accomplish easier to write and reason about. Continuing a trend I see where go tends to have somewhat better primitives, but then obstinately does nothing with them to actually make the higher-level tasks easier to accomplish.

No pinning virtual threads is huge. Finally you can virtual thread with near-wild abandon, as God intended.

Love seeing Streams still getting love. I do a lot of fizzbuzz-esque interviews (the "can you code your way out of a paper bag" type screens) for my company and I think it says a lot that, in general, people who pick Java and use streams pass but people who don't use streams often get tripped up in their loop logic and fail (or, even if they don't fail per se, don't pass). It says a lot about ergonomics and intuitiveness, and also the power of the abstraction to tersely and compactly solve real problems, when a language is a big ally in interviews. And the cool thing about Java streams is that they're as powerful as Ruby's functional-style operation chaining (arr.map{}.reduce(:+) etc) but they're actually performant. I feel it also bears mentioning that people who use Ruby in these interviews, few as they are, almost always pass and do so while writing very few LOC :)

Re:Java 24 by MarkMarine on Tuesday March 18, 2025 @10:43AM (#43400053)
Go is the poster child for not having structured concurrency, the article that started this movement was an explicit take down of go’s concurrency primitive “go func” being dangerous.

https://vorpus.org/blog/notes-on-structured-concurrency-or-g...

I think Kotlin still leads here, and even the Java changes don’t have the same nice ergonomics you get with Kotlin’s DSL. Would love to see more tenseness from Kotlin leak into Java.

Re:Java 24 by pjmlp on Tuesday March 18, 2025 @11:16AM (#43400463)
Yet, like most Go design decisions, they will end up retrofiting what should have been there.

Kotlin has the issue of being a guest language, and wanting to play in many playgrounds, eventually it will diverge as it always happens.

As it is already happening, like now how will Kotlin async deal with virtual threads expectations, including writing portable code that doesn't suffer from runtime semantics, depending on the target platform.

Re:Java 24 by MarkMarine on Tuesday March 18, 2025 @09:42PM (#43407475)
Something better than making everyone take context as the first arg in every function? It’s go’s own brute force way of function coloring, except you have to write it yourself and drag this arbitrary bag of data through every function, what a horrible stapled-on mess.
Re:Java 24 by yubblegum on Tuesday March 18, 2025 @02:38PM (#43403118)
> explicit take down of ... "go func"

I stopped at "go statements are a form of goto statement."

This is simply not correct. They have some diagrams and squinted and said "hey, that looks the same as a goto statement", but unfortunatley they have their diagrams wrong. "go func" will run at scheduler's pleasure, not immediately after the statement "go func..". A goto statement is a deterministic flow control directive. It will goto where you tell it.

Re:Java 24 by MarkMarine on Tuesday March 18, 2025 @04:45PM (#43404869)
you should have read the rest of it then, because in the context of Dijkstra's famous paper [0] (that this is written in the style of) the argument here is being able to understand program flow in the programmers' mind. Your description of the go func actually makes it WORSE, because the program doesn't just go there, it goes there later.

[0] https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.p...

Re:Java 24 by yubblegum on Tuesday March 18, 2025 @04:49PM (#43404903)
That may be true, but regardless, it is most definitely nothing like a goto and it is misleading. & Yes I have read Dijkstra and as it happens have my own critical views regarding Go's goroutines (which are really inspired by CSP), but just don't appreciate misleading assertions. To wit, "flow" does not really make sense in context of concurrency. Flows, plural, sure ..
Re:Java 24 by MarkMarine on Tuesday March 18, 2025 @09:38PM (#43407459)
Well fair, but I do think you should give this article a read. It’s the genesis of kotlin’s coroutines, and other implementations of “structured concurrency” or nurseries as the author conceives of them.
Re:Java 24 by bullen on Tuesday March 18, 2025 @11:00AM (#43400269)
Security Manager is one of the only unique selling points of Java, to remove it (without removing it because you need it underneath) is as big of a blunder as removing Applets from browsers and replacing it with something worse: WASM without GC and then adding GC to WASM...

If SVTwP is not better than NIO; Java ends with JDK 23.

> Warnings issued in JDK 17–23 generated minimal discussion in the Java ecosystem

Because no feature added after 1.8 made sense, so nobody upgraded. They are taking decisions off the wrong data.

> they are encouraged to transition to alternative sandboxing and API interception mechanisms

Feel free to link to anything useful!

Re:Java 24 by atomicnumber3 on Tuesday March 18, 2025 @11:16AM (#43400458)
Unique, sure. Selling point? I really don't think so. This idea of "safely" running untrusted code in the jvm sandbox both never materialized (constant stream of sandbox-escape vulns i've seen over the years) and also was at the wrong level - anyone doing multi-tenant code execution is doing it via things like gvisor or at the OS-level.

I don't think I buy your assertion that nobody has upgraded. I know of a 3000-4000-strong eng org at a certain company that has upgraded all the way from 8 to 17 as of when i left 3 years ago. They primarily wanted the GC improvements because they translated into huge immediate efficiency gains on their workloads (huge Spark/Hadoop spend savings, and moderate savings for the non-big-data jvm workloads).

I do share your lament of applets though. It would've been a way better runtime for portable/install-less/JIT-install things than the current nightmare of html/css/js/etc. But they just didn't have the browser integration - it would've needed to be more than just "look we put a drawing surface into the web browser" - and they didn't have the "window into the world" either (that's browsers). Unfortunately, it's the front door program and platform that owns the users, and that's web browsers.

Re:Java 24 by bullen on Tuesday March 18, 2025 @11:41AM (#43400776)
Can you point to one vuln?

> I don't think I buy your assertion that nobody has upgraded.

Nobody that uses Security Manager has upgraded I meant.

Re:Java 24 by ackfoobar on Monday March 31, 2025 @06:06PM (#43540479)
I grew up hearing about Java vulnerabilities over and over before I really learned programming, so I could not point to any specific ones. But this discussion expresses the same sentiment: https://security.stackexchange.com/questions/57646/why-do-i-...
Re:Java 24 by bullen on Tuesday March 18, 2025 @12:03PM (#43401042)
Found this: https://www.reddit.com/r/java/comments/15ksmm2/javas_securit...

Nothing sticks out, except container companies are probably very happy?

I wonder if the guys working on this did a search before starting: https://github.com/search?type=code&q=AccessController.doPri...

Re:Java 24 by kasperni on Tuesday March 18, 2025 @11:35AM (#43400691)
https://openjdk.org/jeps/486 goes into detail about the motivation for removing support for Security Manager.
Re:Java 24 by bullen on Tuesday March 18, 2025 @11:47AM (#43400845)
I have read it but it does not make sense.

This work is destructive for no reason.

But I am curious how classloaders will work now!?

Re:Java 24 by geodel on Tuesday March 18, 2025 @03:29PM (#43403875)
Huh, it is not no reason. You just do not like their reasons.
Re:Java 24 by bullen on Tuesday March 18, 2025 @07:44PM (#43406627)
I disagree with them, all.

I also dislike the Win32 removal since JDK 22, but I understand that Windows 32-bit assembly is un-maintainable. There is a reason ARM keeps 32-bit.

The Security Manager was not so hard to maintain it merited a removal without replacement.

Re:Java 24 by waste_monk on Tuesday March 18, 2025 @09:47PM (#43407503)
>The Security Manager was not so hard to maintain it merited a removal without replacement.

It sounds like the OpenJDK folk disagree with you, though. From the JEP:

>The Security Manager has not been the primary means of securing client-side Java code for many years, it has rarely been used to secure server-side code, and it is costly to maintain

>...Improve the maintainability of hundreds of JDK classes that currently delegate resource-access decisions to the Security Manager.

>The OpenJDK Core Libraries Group devotes significant time and energy to reviewing every change to any of these methods. Every new API must be designed, and its implementation carefully audited, with the least-privilege model in mind. However, only a tiny number of applications actually enable the Security Manager.

This seems like a big win in terms of maintainability of the core libraries.

Re:Java 24 by oblio on Tuesday March 18, 2025 @11:21AM (#43400516)
There are plenty of places that are at least on Java 11, so I highly doubt the "no one upgraded" part.
Re:Java 24 by bullen on Tuesday March 18, 2025 @11:46AM (#43400832)
I meant to 17 so they would see the warning.
Re:Java 24 by lief79 on Tuesday March 18, 2025 @11:09AM (#43400380)
That has as much to do with Oracle lawyers and ambiguous licensing issues as anything else.
Re:Java 24 by samus on Tuesday March 18, 2025 @06:30PM (#43405949)
The Security Manager was dead as soon as applets ceased to be relevant (which happened a long time before WASM appeared btw.). Deploying the Security Manager requires designing the application up front for it as well as maintaining policy files. Most developers are not aware how to do either.

But its biggest weakness is that it has to restrict a lot of overly powerful APIs. That's like spooning water with a sieve. It would have been better to let the host application restrict which APIs are visible in the first place, like it is done with browser APIs.

The projects that didn't upgrade so far are either dusty business-crirical applications that nobody cares to touch or that utterly deprioritize upgrades unless circumstances force them to. Most of the new features make a lot of sense, but nobody is going to gamble their job on forcing an upgrade just to being able to use them.

To suppress things like `System.exit(0)`, agents can be used. Proper sandboxing solutions would be VMs and containerization technologies. Achieving perfect sandboxing within a process is hopeless anyway.

Re:Java 24 by marwis on Tuesday March 18, 2025 @11:41PM (#43408093)
With some work on better tooling it could've been used to detect and thwart supply chain attacks, which are a growing concern. Process level sandboxing is too coarse.
Re:Java 24 by jayd16 on Tuesday March 18, 2025 @11:41AM (#43400779)
I'm glad they're working on it but I still can't help but my miss async/await.

In C# the API is a bit overturned for sharing a GUI thread but it does the job. Structured Concurrency makes the scopes more obvious but I'm worried about the ergonomics. What is the core use case for the design? Is it just to make collecting a set of concurrent tasks bullet proof? Are we going to see scopes abused and passed around to handle the non-happy path of "a function always ends before it's caller."

It doesn't seem to service GUI programming all that well. I guess there's still Kotlin's approach but hopefully something happens on the Java side.

Re:Java 24 by atomicnumber3 on Tuesday March 18, 2025 @11:52AM (#43400904)
"Is it just to make collecting a set of concurrent tasks bullet proof?"

At a surface level, yeah basically. And ask anyone who's used python's multiprocessing how hard that is to actually get completely right.

I don't think structured concurrency is going to be some panacea of multiprocessing at all. It's to address code you'd see in golang that's like, make a waitgroup, fire off N goroutines, wait for success and gather errors. That code is not incredibly fun in Java right now.

w.r.t. async/await, imo the beauty of virtual threads is that you've no longer got function coloring, and the "await"s are free, implicit, and performant. and of course you're never precluded from using higher level application locks that have always been there, including synchronized now.

Also, specifically w.r.t. gui programming, I think Java is unfortunately kind of stuck. JavaFX has been put into the back of the closet, Swing is completely ossified (though tbh I still like it), and what energy is there behind any non-electron/web GUI development anymore anyway? In a world where vscode, one of the most popular new "IDEs"/IDE platforms, is written in a frickin web browser, and mobile apps dominate a huge % of what constitutes "native" GUI development, I don't really blame Java for not prioritizing it beyond keeping Swing working on e.g. hiDPI displays and so on.

Re:Java 24 by jsiepkes on Tuesday March 18, 2025 @11:37AM (#43400729)
> I really want structured concurrency out of preview!!

I'm guessing they thought it couldn't hurt to do another round of testing. Since OpenJDK 25 will be an LTS release, I suspect it will go out of preview in the next release.

Re:Java 24 by raducu on Tuesday March 18, 2025 @11:10AM (#43400398)
> No pinning virtual threads is huge

Have ALL previous pinning scenarios been resolved, including native calls?

Re:Java 24 by atomicnumber3 on Tuesday March 18, 2025 @11:37AM (#43400717)
ALL? no. but based on my read of the article's linked bit on thread pinning, it seems like it has been substantially resolved, and remaining pinning scenarios are quite rare (they mention you can look for them in JFR).
Re:Java 24 by raducu on Thursday March 20, 2025 @04:06AM (#43420713)
I was wondering if native calls were solved, but I don't see how those can ever be solved
Re:Java 24 by samus on Tuesday March 25, 2025 @03:45AM (#43468855)
In the long term native calls will require a command line flag to be permitted. No matter whether they are done via FFI or JNA. By then, libraries better figure out a way to document them or to reduce using them as much as possible. A lot of off-heap memory trickery should now be possible via (unsafe of course) functions from the FFI library.
Re:Java 24 by neonsunset on Tuesday March 18, 2025 @12:47PM (#43401586)
> Java streams is that they're as powerful as Ruby's functional-style operation chaining (arr.map{}.reduce(:+) etc)

This is not a unique Ruby feature though. Iterators are very common nowadays. Java streams have okay performance, much like .NET's LINQ you likely won't be able to use them in a really performance-sensitive code (although LINQ is improving quite a bit with each new release, overall it performs moderately to significantly faster than Java Streams, but usually slower than Rust iterators).

Re:Java 24 by pjmlp on Tuesday March 18, 2025 @12:59PM (#43401759)
.NET also removed their version of security manager (Code Access Security) for similar reasons.

Just like I expect WebAssembly security conversation to change when folks start plugging components left and right, beyond straight compute logic.

Re:Java 24 by msgilligan on Tuesday March 18, 2025 @01:07PM (#43401852)
> I'm inappropriately smug to have been proven right now, several decades later.

I think you were proven right at least a decade ago. As you said, this is just the final whimper.

Re:Java 24 by scottlamb on Tuesday March 18, 2025 @01:10PM (#43401906)
> No pinning virtual threads is huge. Finally you can virtual thread with near-wild abandon, as God intended.

I see that formerly it pinned virtual threads "when it executes code inside a synchronized block or method", and "frequent pinning for long durations can harm the scalability of an application by capturing carriers". You were supposed to "avoid frequent and long-lived pinning by revising synchronized blocks or methods that run frequently and guard potentially long I/O operations to use java.util.concurrent.locks.ReentrantLock instead."

How big a problem was this in practice? On the one hand, I think "harm the scalability" is putting it mildly—if you have a whole bunch of virtual threads doing IO, only running num_cores of them at once is devastating. On the other hand, holding a lock while doing IO smells wrong. Is this really common?

Re:Java 24 by mping on Tuesday March 18, 2025 @02:39PM (#43403123)
I think in practice it has to do with some libs (eg jdbc drivers) that would be relying on synchronized. If the performance with vthreads was much worse for some cases it would be a bit of failure
Re:Java 24 by re-thc on Tuesday March 18, 2025 @07:55PM (#43406715)
> I think in practice it has to do with some libs (eg jdbc drivers) that would be relying on synchronized.

Those usually have company / community backing that gets it fixed. The irony is you patch the ORM and you patch the JDBC driver only to realize the database pooling library in-between is the 1 that's broken and the author refuses to fix it.

Re:Java 24 by samus on Wednesday March 19, 2025 @06:30AM (#43410209)
Switching `synchronized` for `ReentrantLock` is possible in principle, but it makes the code harder to read and opens the door to subtle concurrency bugs.

Library authors really don't want this kind of code churn for an issue that is not their fault, not their responsibility to solve, and that will get a bugfix before long that maybe even qualifies for a backport to LTS 21.

Re:Java 24 by re-thc on Tuesday March 18, 2025 @07:53PM (#43406699)
> How big a problem was this in practice?

It can deadlock and cause crashes if you do use a library impacted. It's sometimes hard to tell and you'd have to dig into the source. Sometimes the library maintainer wouldn't update the code to a different method for <reasons>.

> Is this really common?

Yes, maybe not in obvious ways e.g. many developers use Spring, which is backed by a large organization and you'd assume to have things covered but under the hood Spring itself uses many libraries and some often open source without much support (can be a personal project by a single developer).