https://discuss.asciidoctor.org/asciidoctorj-and-document-attributes-tp5960p6525.html
rockyallen,
This has come up often and, unfortunately, a limitation of the Asciidoctor processor at the moment. The in-flow document attributes are not available to the AST. They get "played" once when the document is parsed and once again when the document is converted. Depending on where your code runs in processing lifecycle, you may see different values.
What needs to happen is that core needs to designate a node for an attribute entry so they live in the tree. Well, technically, they do live in the tree, but they are in a private area.
Without changing core too much, one possible idea is to make the document attribute accessible via the block (since it's already stored on the block). That might look something like block.getDocumentAttributes(). (These are not the same as block.getDocument().getAttributes()).
I think the next step is to open an issue in asciidoctor/asciidoctor to discuss whether in-flow document attributes should be in the AST and, if so, what are they called, where do they go, and how do we access them.
Cheers,
-Dan