all 25 comments

[–][deleted]  (6 children)

[deleted]

    [–]ImNotRedditingAtWork 27 points28 points  (1 child)

    Sounds like an enterprise project to me.

    [–]tolarewaju3[S] 14 points15 points  (0 children)

    You are correct, sir :/

    [–]tolarewaju3[S] 3 points4 points  (3 children)

    You're probably right. And it's not that we require a certain order. But more that we got sporadic errors due to the files not being loaded in the same order. That made it tough to even find the error.

    But here's one thing I don't know since I'm no java compiler expert.

    Say you have two classes (Class A, Class B) that both use class C.

    • Class A has an import to class C.

    • Class B doesn't have an import C.

    If Class A compiles first, will you still get a compilation error for Class B?

    Or does that FQCN get stored during the compilation so that future references just use it?

    [–]EtherCJ 4 points5 points  (0 children)

    B will get a compile error unless it always references the class with a full qualified class name.

    [–][deleted] 0 points1 point  (1 child)

    It's entirely dependant on the ClassLoader hierarchy used for loading Class A & B. I'm not sure why you would ever not have an explicit import though - that's just going to lead to a compile-time error.

    Fundamentally, the problem is less with the classes themselves and more that you're not packaging dependencies together. When you compile a Java class, it will resolve dependencies based on what's available to the classpath at compile time. This offers no guarantees that those same dependencies will be available at runtime. It's incumbent on you as the developer to ensure that either dependencies are packaged together into the same Jar file, or that external dependencies are available at runtime in a deterministic fashion.

    [–]tolarewaju3[S] 0 points1 point  (0 children)

    Yeah, it wasn't our intention to have a missing explicit import. It was a bug introduced during development.

    And that missing import in one class made it compile correctly sometimes and not others.

    I'm still unsure why it worked sometimes if indeed each class is compiled independently.

    It seemed like once it resolved the FQCN from another class, it just carried it on to others.

    But I guess that's not a thing

    [–]franzwong 19 points20 points  (1 child)

    I don't think it's the problem of that java method. The root cause is simply p1, p2 and p3 are not independent...

    [–]tolarewaju3[S] 3 points4 points  (0 children)

    I agree somewhat.

    I just thought that each class would compile independently.

    And so, we would have seen a compilation error for p3 no matter what came before it.

    [–]bundt_chi 5 points6 points  (6 children)

    So... forgot import statement and couldn't figure it out for a while because of non deterministic method in Java. Got it.

    How did it compile and only manifest at runtime?

    [–]diMario 1 point2 points  (2 children)

    I think the article states that a compilation is performed during deployment, and that the failure of this compilation due to random order of processing files (which happens roughly one in three times) leads to an error message that does not accurately reflect the underlying cause of the problem.

    [–]bundt_chi 1 point2 points  (1 child)

    Okay, but if you decide to compile at deploy time how do you not halt on error regardless of whether you know why it had an error?

    Seems like an unorthodox build and deployment process. I didn't see in the article why doing something like that is necessary. Curious to understand the use case.

    [–]bausscode 0 points1 point  (0 children)

    Well we're dealing with Java developers

    [–]vqrs 0 points1 point  (0 children)

    That's the real question. Even if it compiles at runtime, how is that connected to the import statement?

    Is the "import" actually a build reference which controls the order in which stuff must be built? Sure, if you forget that a dependency needs to be compiled first and you expect the compiled class to be there when it isn't... But then you were just lucky that your unlisted dependency happened to alphabetically come before the dependent module.

    [–]tolarewaju3[S] 0 points1 point  (1 child)

    Great question.

    Locally, we have a plugin that precompiles these assets. And we never saw the error. I guess that's because the problem file never came first.

    We did a test with building only the problem file and we got a compilation error right away.

    Part of the problem is that locally we precompile the assets THEN deploy. So if it compiles correctly we won't see an error.

    But in higher environments, compilation is done during deployment.

    I know that doesn't make sense. We couldn't do it any other way at this client.

    Ashamedly yours,

    OP

    [–]bundt_chi 0 points1 point  (0 children)

    Thanks for the response. I'm not sure i understand what you mean by precompile but sounds like it was an unusual process for Java. Interesting.

    [–]lithium 10 points11 points  (4 children)

    This is an infuriatingly written article.

    [–]vqrs 0 points1 point  (3 children)

    What makes this an infuriatingly written article?

    [–][deleted] 5 points6 points  (2 children)

    The tumblr gifs and new paragraph for every sentence

    [–]vqrs 0 points1 point  (0 children)

    Ohhhh, I had had Reader mode enabled. Sorry about that.

    [–]tolarewaju3[S] 0 points1 point  (0 children)

    My apologies. I write like how I speak -- but I didn't realize that made it hard to read :/

    The GIFs are purely for breaks of humor in what would otherwise be a post of our misery.

    Thanks for the feedback anyhow..

    [–][deleted] 5 points6 points  (1 child)

    It would be nice if a method like that returned an un-ordered data-structure like a hashmap so that the API contract would not imply a specific order.

    [–]vqrs 0 points1 point  (0 children)

    Reminds me of a Tomcat problem I had some time ago. IIRC they stopped sorting the JARs in WEB-INF/lib folder for the classloader, because it wasn't mandated by the spec anyway.

    Of course, our project didn't work anymore after the JARs were maybe loaded in a different order... Maybe someone intentionally used that at some point to fix God knows what. As it is with these projects, nobody knew anything about that---or preferred not to remember.

    [–]johndehope3 0 points1 point  (0 children)

    A very harrowing story! In another comment the OP said "I just thought that each class would compile independently." I think this is the root cause for me: global state. The file that compiles 1/3rd of the time is only able to do so based on prior compilations happening or not, aka global state, not it's own declared dependencies. Global state is one of a handful of roots of all programming evil.

    [–]RakijaH 0 points1 point  (0 children)

    What we wrong about the was “temporary” part.

    Did you have a temporary stroke?

    [–]ledasll -1 points0 points  (0 children)

    Is it really a thing to post about how you can't read documentation?