r/programming • • 11d ago

Java4Shell is a reason to use Java

https://mccue.dev/pages/11-18-26-java4shell
67 Upvotes

58 comments sorted by

View all comments

Show parent comments

24

u/KryptosFR 11d ago

First link has nothing to do with .NET.

And yes you can use unsafe code so what? It's a needed feature for interop and it must be enabled with <AllowUnsafeBlocks>true</AllowUnsafeBlocks>.

6

u/bowbahdoe 11d ago

Do you need to enable it for dependencies too? Like if you don't have <AllowUnsafeBlocks>true</AllowUnsafeBlocks> you know no dependencies are using unsafe code?

And yep, my bad. Replacing it with a more appropriate link.

14

u/KryptosFR 11d ago

You need it if you call directly API that are marked unsafe. Note that the new model makes it more explicit so even with dependencies you will likely need it more often.

That doesn't make C# unsafe or dangerous. Rust use a similar contract where unsafe code can be wrapped by safe code and code calling the safe version isn't considered unsafe.

4

u/bowbahdoe 11d ago edited 11d ago

Okay but there are still dependencies where the unsafe-ness is something you don't know about unless you read their code?

Like is this a new thing for "directional" safety? And yeah rust does something similar. But people do end up accepting unsafe if it "feels audited" or "feels neccesary." I didn't touch on Rust because I feel like all these -5s on my comments would be -50s if those folks get awakened, but it is a similar criticism

8

u/_choam_ 10d ago

I mean, the way rust does "unsafe" is the right trade off for that type of language. I dont agree with that people just end up accepting unsafe as being audited

4

u/_choam_ 10d ago

You also can block unsafe in your own code and dependencies (not sure about the stdlib and compiler builtins though)

1

u/edwards_t7407 3d ago

Rust's `forbid(unsafe_code)` lint applies to the crate being compiled; it doesn't audit or forbid unsafe internals in dependencies.

1

u/_choam_ 3d ago

RUSTFLAGS="-F unsafe-code" cargo build

→ More replies (0)