Week 2: Establishing the Fundamentals

MarvinMarvin
4 min read

馃搮 May 24 - June 1

What I Planned to Do

  • Invoke getRepresentationDescription() and parse the property object to get detailed info about each attribute

  • Collect those attributes and package them in a basic JSON schema

  • Try to work on the edge cases that gets missed in some of the resource classes


What I Worked On

  • This week, I wanted to build upon the foundation I had created with the maven plugin which capsulates getting some kind of property returned from the resource class

  • I had a 1:1 with Chi Bong and we went in depth about various agendas, and I discussed everything I had proposed in my GSoC proposal and how to move forward with it

  • For my first major objective, I was asked to invoke the method that decides what representation returns what properties in each class which was getRepresentationDescription().

  • This class is very tricky in the sense that it calls the RestConstants class which has static initialization inside it and required context that it gets during runtime

  • But as this project was supposed to run during build time it isn鈥檛 afforded the luxury to have that, so my time went in trying to find a way to make that work

  • I want to go deeper in how my initial version of my plugin works which I detail below

  • For the plugin, we start with a URLClassLoader which loads all the classes and resources which are compiled already and kept in the target/classes directory of each omod module

  • This includes all the resource classes, important dependencies and various classes like Representation

  • And this class loader is hierarchical and isolated from the plugin鈥檚 own class loader to avoid conflicts, and can be used independently of it, which is very useful when we want to inspect or load classes compiled in other Maven modules

  • I use reflection in my plugin to scan a particular resource class, for now I have hardcoded it to find the particular resource for simplicity and making the proof-of-concept work

  • It then further uses reflection to find the getRepresentationDescription() method and ready to be invoked

  • Here, we can invoke the no-arg constructor of the resource class and make an instance to invoke the method and get its return values, which proved to be tricky as it depended on context that wasn鈥檛 available

  • I used a method in which we use unsafe allocation to instantiate the resource object without calling the constructor with the sun.misc.Unsafe library

  • But this approach was very primitive and it didn鈥檛 align with the goal to have a robust and proper method to get the properties so I went back from this

  • I then went back to trying with the no-args constructor method and after lot of trial and errors I got it running, but it still wasn鈥檛 able to return proper values for the default representation of the Patient resource

  • After careful debugging and mentor help, I noticed that the code was trying to invoke RestUtils class which was trying to access a static context which crashed the whole process, and commenting it out and running the plugin worked wonderfully!

  • But the other resource classes like ConceptResource and PersonResource couldn鈥檛 run even with this adjustment and trial and error kept on going on until I find out how to maneuver through this


Challenges Faced

  • Invoking getRepresentationDescription() with the resource instance fails and I have to debug and find the cause and solution that solves this

  • Unsafe allocation proved to be very brittle and (as the name suggests) dangerous and unsafe for production use


What I Learned

  • Learnt the concept of class loading and how hierarchical class loading works , and how the class loader interacts with it鈥檚 parent loaders

  • Learnt the use of reflection in more detail, in finding out the output directory where the classes and resources are compiled, finding the method, etc


Commits/PRs This Week


Plans for Next Week

  • Invoke getRepresentationDescription() using no-args constructor and return proper values

  • Clean up the class loader for any redundant classes or any old / primitive methods used

  • Try to find a way to bypass the context needs for the methods we are trying to invoke


Notes/Discussion Points

  • Want to be more descriptive and clearer in my implementation and experimentation of the maven plugin

  • I鈥檒l be on a break from June 2 - June 13 owing to my college examinations which I have prior talked to my mentors and agreed on it


Thank you!

0
Subscribe to my newsletter

Read articles from Marvin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Marvin
Marvin

21 | cs sophomore @ SPIT Mumbai | GSoC 2025 Contributor @ OpenMRS | Backend Dev | Java, Python, Spring Boot, Maven