<div dir="ltr">As far as I know, at time of definition only the class being extended must be available.<div>From your example, this seems to be j.l.Object both times, so this should not be the problem.</div><div><br></div><div>But your case triggers a vague recollection, where I had the same behaviour of </div><div>Lookup.defineClass() in some gnarly unit test of my compiler -- with a NoCDFE that</div><div>I was not able to explain.</div><div><br></div><div>Out of curiosity: what happens when you catch the exception and do a findClass using</div><div>the same lookup and the dotted class name of the class you just tried to define?  In</div><div>my case, I got back the class instance in the catch clause, suggesting the defineClass</div><div>completed after all.</div><div><br></div><div>-- mva</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Am Sa., 15. März 2025 um 10:19 Uhr schrieb John Hendrikx <<a href="mailto:john@int4.org">john@int4.org</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>

  

    
  
  <div>
    <p>Hi list,<br>
      <br>
      I'm trying to use the ClassFile API to automatically implement
      control classes (as found in JavaFX). These classes define inner
      class CssMetaData implementations that refer back to the outer
      class, and the outer class refers to these implementations via
      static fields.  When I define one of the inner types using
      Lookup::defineClass I get a NoClassDefFoundError for the outer
      type.  When I define the outer type first, I get a
      NoClassDefFoundError for one of the inner types.  The situation is
      essentially this:</p>
    <div style="background-color:rgb(255,255,255);padding:0px 0px 0px 2px">
      <div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Consolas;font-size:11pt;white-space:pre-wrap"><p style="margin:0px"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(0,0,160);font-weight:bold">public</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,160);font-weight:bold">class</span><span style="color:rgb(0,0,0)"> Sample {</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">      </span><span style="color:rgb(0,0,160);font-weight:bold">private</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,160);font-weight:bold">final</span><span style="color:rgb(0,0,0)"> Property </span><span style="color:rgb(0,0,192)">b</span><span style="color:rgb(0,0,0)"> = </span><span style="color:rgb(0,0,160);font-weight:bold">new</span><span style="color:rgb(0,0,0)"> Property(</span><span style="color:rgb(0,0,192)">A</span><span style="color:rgb(0,0,0)">);</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">    </span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">      </span><span style="color:rgb(0,0,160);font-weight:bold">private</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,160);font-weight:bold">static</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,160);font-weight:bold">final</span><span style="color:rgb(0,0,0)"> CssMetaData </span><span style="color:rgb(0,0,192)">A</span><span style="color:rgb(0,0,0)"> = </span><span style="color:rgb(0,0,160);font-weight:bold">new</span><span style="color:rgb(0,0,0)"> CssMetaData() {</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">        </span><span style="color:rgb(100,100,100)">@Override</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">        </span><span style="color:rgb(0,0,160);font-weight:bold">public</span><span style="color:rgb(0,0,0)"> Property getProperty(Object obj) {</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">          </span><span style="color:rgb(127,0,85);font-weight:bold">return</span><span style="color:rgb(0,0,0)"> ((Sample)obj).</span><span style="color:rgb(0,0,192)">b</span><span style="color:rgb(0,0,0)">;</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">        }</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">      };</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">    }</span></p><p style="margin:0px">
</p><p style="margin:0px"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(0,0,160);font-weight:bold">abstract</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,160);font-weight:bold">class</span><span style="color:rgb(0,0,0)"> CssMetaData {</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">      </span><span style="color:rgb(0,0,160);font-weight:bold">abstract</span><span style="color:rgb(0,0,0)"> Property getProperty(Object obj);</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">    }</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">  </span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(0,0,160);font-weight:bold">class</span><span style="color:rgb(0,0,0)"> Property {</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">      </span><span style="color:rgb(0,0,160);font-weight:bold">public</span><span style="color:rgb(0,0,0)"> Property(CssMetaData </span><span style="color:rgb(0,0,0);text-decoration:underline wavy rgb(244,200,45)">a</span><span style="color:rgb(0,0,0)">) {</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">      }</span></p><p style="margin:0px"><span style="color:rgb(0,0,0)">    }</span></p></div>
    </div>
    <p></p>
    <p>I'm trying to generate the Sample class.  The classes CssMetaData
      and Propery are pre-existing.  As you can see, Sample refers to A
      in a property it creates, while A refers to that property by
      direct field access after a cast.</p>
    <p>Note that the above is perfectly legal as a Java class, and I
      think the bytecode I generate is correct.  It seems I would need
      to be able to define both classes at the same time, but Lookup
      doesn't seem to have anything for this purpose.</p>
    <p>I'd appreciate any insights!</p>
    <p>--John<br>
    </p>
    <p></p>
  </div>

</blockquote></div>