jOOQ / jOOR

jOOR - Fluent Reflection in Java jOOR is a very simple fluent API that gives access to your Java Class structures in a more intuitive way. The JDK's reflection APIs are hard and verbose to use. Other languages have much simpler constructs to access type meta information at runtime. Let us make Java reflection better.
http://www.jooq.org/products
Apache License 2.0
2.8k stars 377 forks source link

When Reflect.compile(...), if code executed has same ClassName as a previous execution, .class file is never overwritten #106

Closed ANLevant closed 3 years ago

ANLevant commented 4 years ago

Expected behavior and actual behavior:

EXPECTED

//FIRST CALL!!!!
Supplier<String> supplier = Reflect.compile(
    "com.example.HelloWorld",
    "package com.example;\n" +
    "class HelloWorld implements java.util.function.Supplier<String> {\n" +
    "    public String get() {\n" +
    "        return \"Hello World!\";\n" +
    "    }\n" +
    "}\n").create().get();
// Prints "Hello World!"
System.out.println(supplier.get());

//SECOND CALL!
Supplier<String> supplier = Reflect.compile(
    "com.example.HelloWorld",
    "package com.example;\n" +
    "class HelloWorld implements java.util.function.Supplier<String> {\n" +
    "    public String get() {\n" +
    "        return \"ByeBye World!\";\n" +
    "    }\n" +
    "}\n").create().get();

// Prints "ByeBye World!"
System.out.println(supplier.get());

ACTUAL

//FIRST CALL!!!!
Supplier<String> supplier = Reflect.compile(
    "com.example.HelloWorld",
    "package com.example;\n" +
    "class HelloWorld implements java.util.function.Supplier<String> {\n" +
    "    public String get() {\n" +
    "        return \"Hello World!\";\n" +
    "    }\n" +
    "}\n").create().get();
// Prints "Hello World!"
System.out.println(supplier.get());

//SECOND CALL!
Supplier<String> supplier = Reflect.compile(
    "com.example.HelloWorld",
    "package com.example;\n" +
    "class HelloWorld implements java.util.function.Supplier<String> {\n" +
    "    public String get() {\n" +
    "        return \"ByeBye World!\";\n" +
    "    }\n" +
    "}\n").create().get();

// Prints "Hello World!"
System.out.println(supplier.get());

Steps to reproduce the problem:

  1. Make a Reflect.compile(...) call
  2. Make another Reflect.compile(...) call with changes on the class code BUT THE SAME CLASS NAME

Versions:

lukaseder commented 3 years ago

Thanks for your request. This is a duplicate of https://github.com/jOOQ/jOOR/issues/72.

I agree we should offer a way to override the default behaviour of using the caller class loader in order to be able to re-define classes compiled with this API.