If I read the JLS §8.1.6 and §9.1.4 correctly, the classes that a sealed class/interface permits, are just the direct subclasses/interfaces. To illustrate this, consider the following example: If I understand the specification correctly, I1 obviously permits C and D but not E and F (via the extends hierarchy of I2 from I1). Is this correct? The reason I’m asking
Tag: java-17
Why does jshell show this number?
I am learning java and this logic makes me feel confused. Isn’t here i=20(+1)+20(+1)? Why 41 instead of 42? See this code run at Ideone.com. Answer Effectively, the expression i=i++ + i++; is equal to i=i++ + i;. Why? The latter i++ result value is never used and is not propagated. The result of the postfix addition i++ is used
Prototyped bean not triggering Scheduled method in Spring Boot
I’m using Java 17, spring-boot 2.7.3 and spring 5.3.22 dependencies. I have prototyped beans as follows: My application class: I annotated the InsertTransactionDetailsByScheduleAPIInteractor also as prototype in order to have a new instance of the inner beans per schedule execution, but somehow the @Scheduled method only runs when I have a singleton InsertTransactionDetailsByScheduleAPIInteractor bean, which in my use case I
Running unit tests with Spark 3.3.0 on Java 17 fails with IllegalAccessError: class StorageUtils cannot access class sun.nio.ch.DirectBuffer
According to the release notes, and specifically the ticket Build and Run Spark on Java 17 (SPARK-33772), Spark now supports running on Java 17. However, using Java 17 (Temurin-17.0.3+7) with Maven (3.8.6) and maven-surefire-plugin (3.0.0-M7), when running a unit test that uses Spark (3.3.0) it fails with: java.lang.IllegalAccessError: class org.apache.spark.storage.StorageUtils$ (in unnamed module @0x1e7ba8d9) cannot access class sun.nio.ch.DirectBuffer (in module
Unsupported class file major version 61
I am trying to integrate Glowroot into my Java application. Unfortunately, I get the following error: Neither Glowroot nor my application seem to use gradle so I have no idea where this incompatibility is coming from. Have you got any idea on how I could find the source of the incompatibility and then how I could fix it? Thank you!
How to generate self-signed certificate in Java with JDK17
tl,dr; Is there a native Java17 solution to generate self-signed certificate, either via standard library (very unlikely) or some slim, lightweight library? There is a similar question (Access `sun.security.x509` in JDK 11 without modules?, asked by me) because starting with JDK11 access to internal JDK packages has been limited thus it’s not possible to use classes from sun.security.x509. Up until
Criteria for default garbage collector Hotspot JVM 11/17
I found a source describing that the default gc used changes depending on the available resources. It seems that the jvm uses either g1gc or serial gc dependnig on hardware and os. The serial collector is selected by default on certain hardware and operating system configurations Can someone point out a more detailed source on what the specific criteria is
Error when trying to set up JDBC connection with local MYSQL database in Java 17 with a spring boot project
My project is generated/downloaded from: https://start.spring.io/ I am now trying to connect to my local MYSQL database which actually has data in it and is fully functional. To do this I am using a springboot project where I want to set up a jdbc connection, as I was able to do before in Java 8. But now when I run
void with Generics in Java
I have a function that returns void Generic method Implementation of generic interface How can I use void in IRequestHandler<DeleteProductCommand, Void> so that I can map void from iProductService.delete(deleteProductCommand.id); Answer Option 1: Just return null: Option 2: Update the IProductService::delete method to return something meaningful, e.g. a boolean value like Collection::remove does:
ArrayIndexOutOfBoundsException while getting values from hashmap in Java 17
I have a static HashMap<UUID, MyObject> ALL = new HashMap<>(); which is used in multi-threading. To reproduce the error, I made this code: But, after some seconds (around 10), I get this error with Java 16 and Java 17: With Java 8, I get this: To test, I remove synchronized key-word, then try again in Java 17 and I get