What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

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.

share|improve this question
4  
FWIW, leading off a question with a big block of code is usually a bad idea... –  Shogging through the snow May 28 '10 at 18:56
    
Agreeing with Shog here. It really is better to have some manner of introduction. –  Grace Note May 28 '10 at 18:57
    
I agree with @Shog9 and @ccomet, but some really, really weird things happen on edit! –  The Unhandled Exception May 28 '10 at 18:57
    
Stand by, updated answer with FHC coming soon... –  The Unhandled Exception May 28 '10 at 19:00
2  
@Shog9. I agree here, but the bug is a bug. –  Alexander Pogrebnyak May 28 '10 at 19:31
1  
@Alexander: It's not a bug, it's a feature ;-) –  The Unhandled Exception May 28 '10 at 19:38
    
@Josh. How could I forget? And in case it's not a feature, it's always an inconsistency or software problem. –  Alexander Pogrebnyak May 28 '10 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. –  Frank A. Krueger May 29 '10 at 22:33
    
@Frank. Yeah, I don't understand, because it's definitely repro right here on my screen. –  Alexander Pogrebnyak Jun 2 '10 at 16:31
    
Just came across this at stackoverflow.com/questions/4008104/… –  Andrew Grimm Oct 24 '10 at 22:38

4 Answers 4

up vote 3 down vote accepted

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 2 3

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 {
share|improve this answer
    
But there is no text before the code. –  mmyers May 28 '10 at 18:43
    
There was an   –  The Unhandled Exception May 28 '10 at 18:48
    
And there isn't in this question. I take everything I said back! –  The Unhandled Exception May 28 '10 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. –  Alexander Pogrebnyak May 28 '10 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 May 28 '10 at 19:35
    
WHAT? I don't believe you @ccomet. Did you look it up in the Unicorn dictionary or something? –  The Unhandled Exception May 28 '10 at 19:37
 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.
share|improve this answer
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.

share|improve this answer
    
@Jeff: Did you edit it, make no changes, and save? I believe this is an issue with editing, not posting initially –  The Unhandled Exception May 28 '10 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 May 28 '10 at 19:21
    
I swear I'm not crazy!!! Well maybe I am but I wasn't seeing things :-) –  The Unhandled Exception May 28 '10 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. –  The Unhandled Exception May 28 '10 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. –  Dan McGrath Jun 3 '10 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 '10 at 21:40
    
It is reproduceable. I came across it today. –  Andrew Grimm Oct 24 '10 at 22:39

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.

share|improve this answer

You must log in to answer this question.

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