<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Philip Mahama Akpanyi</title>
    <description>The latest articles on DEV Community by Philip Mahama Akpanyi (@felipey2010).</description>
    <link>https://dev.to/felipey2010</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F682983%2Fb90d1ba4-1b4a-4192-a20d-b0c8e72bbbc6.png</url>
      <title>DEV Community: Philip Mahama Akpanyi</title>
      <link>https://dev.to/felipey2010</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/felipey2010"/>
    <language>en</language>
    <item>
      <title>[IntelliJ Fix] Fixing Spring Boot Startup Exception: java.lang.reflect.InaccessibleObjectException "opens java.lang"</title>
      <dc:creator>Philip Mahama Akpanyi</dc:creator>
      <pubDate>Wed, 04 Dec 2024 01:02:14 +0000</pubDate>
      <link>https://dev.to/felipey2010/intellij-fix-fixing-spring-boot-startup-exception-javalangreflectinaccessibleobjectexception-47b</link>
      <guid>https://dev.to/felipey2010/intellij-fix-fixing-spring-boot-startup-exception-javalangreflectinaccessibleobjectexception-47b</guid>
      <description>&lt;p&gt;If you've encountered the &lt;code&gt;java.lang.reflect.InaccessibleObjectException&lt;/code&gt; error while working on a Spring Boot project in IntelliJ, you're not alone! This issue often arises due to stricter module access restrictions in newer Java versions as explained &lt;a href="https://www.springcloud.io/post/2022-07/inaccessibleobjectexception/#gsc.tab=0" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;br&gt;
When I created a Spring Boot project in IntelliJ, the application refused to start, throwing the following exception:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37abodkk471bmp0w179o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37abodkk471bmp0w179o.png" alt="Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field java.lang.ThreadLocal$ThreadLocalMap java.lang.Thread.threadLocals accessible: module java.base does not " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This error is common when you're working with Java modules and missing the necessary --add-opens option to grant access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Solution&lt;/strong&gt;&lt;br&gt;
After some research, I discovered &lt;a href="https://github.com/pinterest/ktlint/issues/1391#issuecomment-1557236615" rel="noopener noreferrer"&gt;here&lt;/a&gt; that adding the JVM argument &lt;code&gt;--add-opens java.base/java.lang=ALL-UNNAMED&lt;/code&gt; can resolve the issue. However, the tricky part was figuring out where to apply this fix in IntelliJ.&lt;/p&gt;

&lt;p&gt;Here’s how I resolved it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open IntelliJ Run/Debug Configurations: Go to Run &amp;gt; Edit Configurations in the top menu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgxi9l694iamm7ky9sh0j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgxi9l694iamm7ky9sh0j.png" alt="Run/Debug Configurations" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Locate Your Application: Select your Spring Boot application configuration. I use Wildfly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add JVM Options: In the "VM options" field, add: &lt;code&gt;--add-opens java.base/java.lang=ALL-UNNAMED&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apply and Run: Save the changes, re-run your application, and voilà! No more startup exceptions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5slk80pxicnkop7sbzgv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5slk80pxicnkop7sbzgv.png" alt="Add --add-opens java.base/java.lang=ALL-UNNAMED" width="800" height="690"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Takeaway&lt;/strong&gt;&lt;br&gt;
This fix works because it explicitly allows the JVM to open restricted modules to your application. Keep in mind that while this resolves the issue, it’s always good to stay informed about modularity and related best practices.&lt;/p&gt;

&lt;p&gt;Have you encountered similar issues? Feel free to share your experience or any alternative solutions in the comments!&lt;/p&gt;

</description>
      <category>springboot</category>
      <category>fix</category>
      <category>inaccessibleobjectexception</category>
      <category>java</category>
    </item>
  </channel>
</rss>
