<Beans Dev> Fwd: Re: [PATCH] test/jdk/java/beans/PropertyEditor/Test6397609.java failed in JITed code

Alan Bateman Alan.Bateman at oracle.com
Sun Jan 6 09:37:51 UTC 2019


On 04/01/2019 08:47, Fu Jie wrote:
> Hi,
>
> I think Alan's approach is more readable and more elegant.
> And it can also fix the issue mentioned by Sergey.
If I read this patch correctly then the isEditorExist is just checking 
that there has been some reference processing but it doesn't guarantee 
that the editor class has been unloaded.

Here's an alternative to consider:

         Class<?> targetClass = Object.class;
         Class<?> editorClass = new MemoryClassLoader().compile("Editor",
                 "public class Editor extends 
java.beans.PropertyEditorSupport {}");
         PropertyEditorManager.registerEditor(targetClass, editorClass);

         if (PropertyEditorManager.findEditor(targetClass) == null) {
             throw new Error("the editor is lost");
         }

         // allow, and wait for, Editor class to be unloaded
         var ref = new WeakReference<Class<?>>(editorClass);
         editorClass = null;
         while (ref.get() != null) {
             Thread.sleep(100);
             System.gc();
         }

         if (PropertyEditorManager.findEditor(targetClass) != null) {
             throw new Error("unexpected editor is found");
         }

As regards looping until a weak ref has been cleared then we do this in 
many tests. I've no doubt that many tests and features would fail with 
-DisableExplicitGC but this shouldn't be a concern here.

-Alan


More information about the beans-dev mailing list