5
class Student {

  private String name;

  public Student(String name){
         this.name = name;
  }
  public String getName(){
         return name;
  }
}

class StudentServer {


   public StudentServer(){

          Student[] s = new Student[30];
          s[0] = new Student("Nick");

          System.out.println(s[0]); // LINE 01:But this compiles, although prints junk

          System.out.println(s[0].getName()); // LINE 02:I get a error called cannot find symbol
   }

  public static void main(){
         new StudentServer();
  }
}

The above example appeared in this question. Somebody made edits and deleted some formatting from the start of the question, now class Student { appears as regular text, not Code.
What's weird is that it appears right in the preview window.

10
  • 5
    FWIW, leading off a question with a big block of code is usually a bad idea...
    – Shog9
    May 28, 2010 at 18:56
  • Agreeing with Shog here. It really is better to have some manner of introduction.
    – Grace Note StaffMod
    May 28, 2010 at 18:57
  • I agree with @Shog9 and @ccomet, but some really, really weird things happen on edit! May 28, 2010 at 18:57
  • Stand by, updated answer with FHC coming soon... May 28, 2010 at 19:00
  • 2
    @Shog9. I agree here, but the bug is a bug. May 28, 2010 at 19:31
  • 1
    @Alexander: It's not a bug, it's a feature ;-) May 28, 2010 at 19:38
  • @Josh. How could I forget? And in case it's not a feature, it's always an inconsistency or software problem. May 28, 2010 at 19:45
  • I posted this exact bug awhile back: meta.stackexchange.com/questions/39612 Jeff likes closing it as no repro even though it's pretty simple to repro. May 29, 2010 at 22:33
  • @Frank. Yeah, I don't understand, because it's definitely repro right here on my screen. Jun 2, 2010 at 16:31
  • Just came across this at stackoverflow.com/questions/4008104/… Oct 24, 2010 at 22:38

4 Answers 4

3

EDIT4: OK. Found what caused the strange behavior below. Steps to reproduce:

  1. Post a question which starts with a blank line followed by a code block. It looked incorrect
  2. Edit the question. The blank line is automatically gone. Make absolutely no changes.
  3. Now, the code block is correct. Which make sense because the blank line was automagically removed.

EDIT3: OK, some weird things happen when a question starts with code and it gets edited. Here's what I did:

  1. Post a question which starts with a code block. It looked incorrect
  2. Edit it and make absolutely no changes.
  3. Now, the code block is correct!

Screen captures with beveled freehand circles + drop shadows:

1
(source: gitlin.name)
2
(source: gitlin.name)
3
(source: gitlin.name)

EDIT2: Seems like something weird happens on edit... look at this test question!

EDIT: Trying to reproduce this. Disregard the following previous answer, it seems to be inaccurate:

You need a line of whitespace between text and code. The following won't work:

 
    class Student {

The following will:

 

    class Student {

Here are the two un-code-ed (view edit history to see source):


  class Student {


 

class Student {
6
  • But there is no text before the code.
    – mmyers
    May 28, 2010 at 18:43
  • There was an   May 28, 2010 at 18:48
  • And there isn't in this question. I take everything I said back! May 28, 2010 at 18:49
  • Josh, I think you are onto something. I think right after I've posted the question it looked OK. Then I clicked edit and without even saving it looked at this again. It was wrong at that time. May 28, 2010 at 19:32
  • 1
    I finally decided to look it up, because it really bothered me that everyone keeps using it... and good gravy, "automagically" is a real dictionary word.
    – Grace Note StaffMod
    May 28, 2010 at 19:35
  • WHAT? I don't believe you @ccomet. Did you look it up in the Unicorn dictionary or something? May 28, 2010 at 19:37
3
 Don't ask me why it works
 but if you use 5 spaces instead of 4
 you can start off with a code block properly.
1

Just came across this exact problem on this question.

Despite the preview from Markdown being correct the displayed post had a problem. In particular, I edited the title, didn't change the question, saved the change. When I went back to the question I noticed the code was no longer displaying correctly.

I added a line between the top of the post and the first line of code, this maintained the error on a subsequent edit.

As I was about to post a bug here, noticed this question, removed the line at the top of the code (which was actually omitted when I clicked edit) and saved the changes, formatting was correct.

-2
this is a line of code
this is another line of code

Above is

    this is a line of code
    this is another line of code

edit: no repro. Pasted this in as a new question on our development tier and it comes out as code.

edit2: testing editing, no changes.

7
  • @Jeff: Did you edit it, make no changes, and save? I believe this is an issue with editing, not posting initially May 28, 2010 at 19:20
  • When I tested it earlier, it did not work (no escape on first line), but less than a minute later, it worked as it should. No repro here anymore, either.
    – Grace Note StaffMod
    May 28, 2010 at 19:21
  • I swear I'm not crazy!!! Well maybe I am but I wasn't seeing things :-) May 28, 2010 at 19:26
  • 1
    @ccomet and @Jeff: I wasn't crazy but my answer wasn't accurate either. See my updated answer, it happens when the question starts with a blank line and then code. May 28, 2010 at 19:33
  • 1
    I just witnessed this on an edit I performed on SO. First line was a codeblock which was fine in preview, but rendered incorrectly on saving. Clicking edit again confirmed that it was still correct on preview. Jun 3, 2010 at 13:18
  • Yet another one. Just posted this answer and had a lot of trouble trying the first code line work. It would seem fine in the preview but look unformatted on the actual page. I finally used 5 spaces instead of 4, as suggested above, which made it look as expected, and then removed the extra space in the next edit, and only then it was all right. Very strange.
    – GSerg
    Oct 21, 2010 at 21:40
  • It is reproduceable. I came across it today. Oct 24, 2010 at 22:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .