Thorinwasher
JCHJava Community | Help. Code. Learn.
•Created by Thorinwasher on 11/13/2024 in #java-help
How to find generics when running a java process
I'm generating code out of code. To do this I need to scan code to generate the code, this includes generics. Currently I'm using classgraph as the scanner for the code, but it does not look like it supports generics (I believe it's runtime, so generics don't exist there).
Does anyone know a way to programmatically fetch generics from a library?
6 replies
JCHJava Community | Help. Code. Learn.
•Created by Thorinwasher on 9/21/2024 in #java-help
Asyncronous task queue
I have one thread that delegates tasks over to another thread, which runs those tasks in a queue. These tasks are blocking tasks (database), that I want to be run in the correct order, first in first out.
Currently using BlockingQueue, but when testing it using junit, it can freeze the whole test. That's because after each test, this thread is waited on until it finishes. I have not found a good way to enable/disable the queue
How would one do this properly?
53 replies
JCHJava Community | Help. Code. Learn.
•Created by Thorinwasher on 7/27/2024 in #java-help
Issue with multimodule project
I'm trying to publish my project to maven central, but I get this error.
I have been banging my head against the wall trying to solve this problem for half a day now, anyone got an idea what the issue is?
Here's one of my build files: https://github.com/Thorinwasher/BlockAnimator/blob/main/api/build.gradle.kts
5 replies
JCHJava Community | Help. Code. Learn.
•Created by Thorinwasher on 6/15/2024 in #java-help
Gradle shade not shading in one operating system, but does in another
I made a docker container meant to build all my paper plugins (minecraft server). The problem is that by somre reason, it does not shade what is otherwise being shade when I run the same command in my OS (windows)
Does anyone have a clue what would be the case? I'm quite new to gradle, so that might be the cause. Here's part of the build script:
I run the following process with the command
gradle clean install
:
5 replies
JCHJava Community | Help. Code. Learn.
•Created by Thorinwasher on 5/21/2024 in #java-help
Classloader that has higher priority than parent
I need to change the class loader that is in use when testing a mock framework, which is because the API I'm mocking needs specific class loader to instantiate a class.
Thankfully this is possible to do using LauncherInterceptors (JUnit) with custom claass loader implementation. But I have encountered some issues:
- Some classes has already been loaded by the default class loader. The custom class loader needs to be able to fetch these class references of the default class loader.
- Except for the above case and if the class is in a java standard library, the class needs to be loaded by the custom class loader. this is because the class loader that is selected when loading classes seems to be the same class loader that loaded the previous class (Not 100% sure on this, but purely based on behavior this seems to be the case)
Let me just write a workflow of what I think would be necessary for this to work:
1. First check default class loader if the class has already been loaded by it, if that's the case use that class.
2. Try to load the class with Bootstrap class loader (java standard libraries)
3. Try to load the class using the custom class loader implementation (Will use same resources as default class loader)
4. Load the class using child implementations.
The problem with that workflow is that I can't find a way do part 1. It does not seem to be possible to get only previously loaded classes from another class loader instance in java versions after java 9. There was a way previously where you could access a protected method in the class loader, but now that has been access restricted
7 replies
JCHJava Community | Help. Code. Learn.
•Created by Thorinwasher on 4/29/2024 in #java-help
How to change one system property without code or from command line
I'm developing a mocking framework and I need to change the class loader that unit uses to something else (This is due to a property of the API I'm mocking). I found that you can do this reliably in Junit by creating a custom LauncherInterceptor. The problem is that a system property needs to be assigned for this LauncherInterceptor implementation to be found.
I'm therefore wondering if it's possible to set a system property from a library that will later be used during tests for other projects. The user should preferably not have to do anything. Yes, there is the
System.setProperty
function, but this requires a class to be loaded for this to work, which might not reliably be the case.6 replies
JCHJava Community | Help. Code. Learn.
•Created by Thorinwasher on 4/23/2024 in #java-help
How to convert from .pem to .p12
More specifically; how to read privkey.pem file and fullchain.pem file and convert that into a byte array with the format of p12 in java. (I know there's somehing called OpenSSL which can do this.
I found a guide online which uses he BouncyCastle library to do this, the issue is that these solutions does not work on the latest version because of api changes.
For even more context: I have certbot and that produces .pem files. I have written a simple server in jersey, which I want to be able to establish https connections with. But that does not seem to support .pem files, but rather .p12 files. Simple solution to this is to convert the files manually, but that will not be sustainable in the longrun, thus my question.
16 replies
JCHJava Community | Help. Code. Learn.
•Created by Thorinwasher on 12/10/2023 in #java-help
Server mocking framework: Load a plugin that already has been loaded before unit test. Impossible?
Background
I'm a developer of a mocking framework, which is used to test plugins for minecraft servers. One of the main functionalities of that mocking framework is the ability to load plugin classes, which holds the initial methods triggered whenever the plugin is enabled.
Here comes one issue, when running a real minecraft server these plugins are loaded with separate classloaders, which means that every internal resource of each plugin will be isolated. This will not be the case for our mocking framework, as all plugins are loaded by the SystemClassLoader (or whatever the default java class loader is called). That means that if you're loading multiple plugins, then there is a possibility of a clash between internal file names.
Another issue is that the API we're using requires us to have a specific classloader for the plugin class. We're using ByteBuddy to deal with this. But it throws exceptions whenever plugin classes are defined as final.
The solution I'm searching for
Anyhow, that's the background for my problems. I'm therefore wondering if there's any way to load a class that already has been loaded and substitute all the reference of the old class to the new class. Or something similar.
From what I know, this is not possible (and probably should not be), but is there anything that would achieve a similar result?
4 replies