Skip to content

Demonstrate runtime failure caused by flat directory vs package decla…#9

Open
mvcatsifma wants to merge 1 commit into
mainfrom
demo/package-structure-issue
Open

Demonstrate runtime failure caused by flat directory vs package decla…#9
mvcatsifma wants to merge 1 commit into
mainfrom
demo/package-structure-issue

Conversation

@mvcatsifma
Copy link
Copy Markdown

Bug on main branch: flat com.hyfacademy/ directory causes runtime ClassNotFoundException

The starter repo ships with a flat task-1/com.hyfacademy/ directory (literal dot
in the folder name). The assignment spec requires proper Java package structure, so
students are expected to add package com.hyfacademy;, package com.hyfacademy.model;, etc.

The problem: javac accepts these package declarations regardless of where the
file sits, so compilation passes. But at runtime, the JVM looks for
com/hyfacademy/Main.class (nested directories) and fails because the .class
files live in com.hyfacademy/ (flat, literal dot).

Reproduce

javac task-1/com.hyfacademy/Main.java ...   # exits 0 — no errors
java -cp task-1/com.hyfacademy com.hyfacademy.Main
# Error: Could not find or load main class com.hyfacademy.Main
# Caused by: java.lang.ClassNotFoundException: com.hyfacademy.Main

Impact

Every student who correctly adds package declarations (as required) will hit this
runtime failure. It is not caused by their code — it is caused by the starter
directory structure.

Options

  1. Fix the starter repo — rename task-1/com.hyfacademy/ to task-1/com/hyfacademy/
    and add package declarations to the stub files.
  2. Leave it intentional — document in the assignment brief that restructuring the
    directory is part of the task ("implement the correct file structure").

…rations

All four files compile cleanly with javac, but the JVM cannot find
com.hyfacademy.Main at runtime because the directory is named
com.hyfacademy (literal dot) instead of the nested com/hyfacademy/
structure that Java package resolution requires.

Verified: javac exits 0, java throws ClassNotFoundException.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant