Resolution: Won't Do
Affects Version/s: 3.1.4
Fix Version/s: None
Component/s: Extensions API
When I was developing a new extension to extend the support of UML in class diagram, I found that a newly created inheritance dependency can disappear after the first time compilation and appear again after the second time compilation.
The fault is related to a statement "bClassTarget.getBClass().getFields();" which can be involved in "ExtensionClassTargetPainter.drawClassTargetForeground(...)"
The fault can be triggered by the following extension with some steps:
CREATE AN INHERITANCE
1. Install the following extension (see the codes or attached JAR)
2. Create two classes in the project
3. Add an 'inheritance' dependency between them
4. Click compile button on the left-hand side panel
The bug is triggered and the 'inheritance' dependency DISAPPEARS now.
5. Right click on the 'child' class and select compile
The 'inheritance' dependency appears now.
REMOVE AN INHERITANCE
6. Right click on the 'inheritance' dependency and select remove
7. Click compile button on the left-hand side panel
The bug is triggered again. The 'inheritance' dependency, which should be removed, APPEARS now.
8. Right click on the 'child' class and select compile
The 'inheritance' dependency disappears now.
Here is the complete source codes of the bug-triggering extension:
Renew the ClassLoader after ClassTarget compilation can resolve this problem. However, I'm not sure if there is any side-effect.
Here is the code. I added 'getPackage().getProject().removeClassLoader();' before Package object invoking 'getProject().getClassLoader()' in 'loadClass(...)' method. And then the problem is solved.
I guess that the ClassLoader, which is removed before compilation and should only be reloaded after compilation, is reloaded before the completion of the compilation. And that unexpected reloading action may be caused by the extension which indirectly invokes 'Project.getClassLoader()' in the interface 'ExtensionClassTargetPainter.drawClassTargetForeground(...)' and breaks the assumed reloading sequence. As a result, the mechanism which reflects source code into class diagram applies the outdated class information.
BlueJ run started: Fri Nov 28 12:47:56 CST 2014
BlueJ version 3.1.4
Java version 1.8.0_20
Virtual machine: Java HotSpot(TM) Client VM 25.20-b23 (Oracle Corporation)
Running on: Windows 7 6.1 (x86)
Java Home: C:\Program Files (x86)\BlueJ-314\jdk\jre